Unloading and Loading Columns Containing Final Object Types

Final column objects are populated into an external table by moving each attribute in the object type into a column in the external table. In addition, the external table needs a new column to track whether the column object is atomically NULL. The following steps demonstrate the unloading and loading of columns containing final object types.

  1. In the following example, the warehouse column in the external table is used to track whether the warehouse column in the source table is atomically NULL.
    SQL> CREATE TABLE inventories_obj_xt
      2  ORGANIZATION EXTERNAL
      3  (
      4    TYPE ORACLE_DATAPUMP
      5    DEFAULT DIRECTORY def_dir1
      6    LOCATION ('inv_obj_xt.dmp')
      7  )
      8  AS
      9  SELECT oi.product_id,
     10         DECODE (oi.warehouse, NULL, 0, 1) warehouse,
     11         oi.warehouse.location_id location_id,
     12         oi.warehouse.warehouse_id warehouse_id,
     13         oi.warehouse.warehouse_name warehouse_name,
     14         oi.quantity_on_hand
     15  FROM oc_inventories oi;
    
    Table created.
    

    The columns in the external table containing the attributes of the object type can now be used as arguments to the type constructor function when loading a column of that type. Note that the warehouse column in the external table is used to determine whether to call the constructor function for the object or set the column to NULL.

  2. Load a new internal table that looks exactly like the oc_inventories view. (The use of the WHERE 1=0 clause creates a new table that looks exactly like the old table but does not copy any data from the old table into the new table.)
    SQL> CREATE TABLE oc_inventories_2 AS SELECT * FROM oc_inventories
    WHERE 1 = 0;
    
    Table created.
    
    SQL> INSERT INTO oc_inventories_2
      2  SELECT product_id,
      3         DECODE (warehouse, 0, NULL,
      4                 warehouse_typ(warehouse_id, warehouse_name,
      5                 location_id)), quantity_on_hand
      6  FROM inventories_obj_xt;
    
    1112 rows created.