sql >> Database teknologi >  >> RDS >> Oracle

Hvordan indsætter man en værdi i en indlejret tabel uden at miste data i den tabel?

Brug MULTISET UNION [ALL|DISTINCT] operatør:

SQL Fiddle

Oracle 11g R2 Schema Setup :

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'
/
 

Forespørgsel 1 :

SELECT *
FROM   category
 

Resultater :

| NAME | BUSINESSES | |------------|------------------------------| | Restaurant | xzqpehc234ajdpa8,other_value |

Forespørgsel 2 :

Eller brug en bindevariabel til at inkludere samlingen i forespørgslen:

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;
 

Forespørgsel 3 :

SELECT name, CARDINALITY( businesses )
FROM   Category
 

Resultater :

| NAME | CARDINALITY(BUSINESSES) | |--------------|-------------------------| | lots of data | 10000 | | Restaurant | 2 |


  1. antal rækker, der forekommer for hver dato i kolonnens datointerval

  2. netbeans xdebug venter på forbindelse på trods af at jeg har gennemgået alle forumsvar

  3. NetSuite-migreringer

  4. MySQL – Forbindelsesfejl – [MySQL][ODBC 5.3(w)-driver]Værten 'IP' har ikke tilladelse til at oprette forbindelse til denne MySQL-server