Użyj MULTISET UNION [ALL|DISTINCT]
operator:
Konfiguracja schematu Oracle 11g R2 :
CREATE OR REPLACE TYPE businessTableForCategories AS TABLE OF VARCHAR(128);
/
CREATE TABLE Category (
name VARCHAR(128) PRIMARY KEY,
businesses businessTableForCategories
) NESTED TABLE businesses STORE AS categoryBusinessTable
/
INSERT INTO Category VALUES (
'Restaurant',
businessTableForCategories('xzqpehc234ajdpa8')
)
/
UPDATE Category
SET businesses = businesses
MULTISET UNION ALL
businessTableForCategories('other_value')
WHERE name = 'Restaurant'
/
Zapytanie 1 :
SELECT *
FROM category
Wyniki :
| NAME | BUSINESSES |
|------------|------------------------------|
| Restaurant | xzqpehc234ajdpa8,other_value |
Zapytanie 2 :
Lub użyj zmiennej bind, aby uwzględnić kolekcję w zapytaniu:
DECLARE
businesses businessTableForCategories := businessTableForCategories();
BEGIN
businesses.EXTEND( 10000 );
FOR i IN 1 .. 10000 LOOP
businesses(i) := DBMS_RANDOM.STRING( 'x', 128 );
END LOOP;
INSERT INTO Category VALUES ( 'lots of data', businesses );
END;
Zapytanie 3 :
SELECT name, CARDINALITY( businesses )
FROM Category
Wyniki :
| NAME | CARDINALITY(BUSINESSES) |
|--------------|-------------------------|
| lots of data | 10000 |
| Restaurant | 2 |