如何插入REF表?

时间:2011-04-26 02:34:50

标签: oracle plsql oracle10g

CREATE TYPE artist_table_type AS TABLE OF REF artist_type;
/                                                         

INSERT INTO track_table VALUES (                              
   1,                                                     
   'test title',                                          
   123,                                                   
   to_date('12-09-1989', 'dd-mm-yyyy'),                   
   artist_table_type(                                     
            -- What goes here???
   ),                                                     
   artist_table_type());  

我想在此表中插入一个对象的引用嵌套表。我可以这样做吗?我不得不取消这张桌子吗?

2 个答案:

答案 0 :(得分:1)

您可以使用COLLECT和CAST函数在SQL中创建嵌套表。例如,如果你想根据某些条件从其他表中选择艺术家对象,我相信这应该有效:

INSERT INTO track_table
  SELECT
   1,
   'test title',
   123,
   to_date('12-09-1989', 'dd-mm-yyyy'),
   CAST(COLLECT(REF(artists)) AS artist_table_type)
   artist_table_type()
  FROM
   artists
  WHERE <whatever the condition is for selecting the appropriate artists>
  ;

答案 1 :(得分:-1)

INSERT INTO TABLE(this table is syntax dont think its name of the table..)

(SELECT t.nested_tbl_colm 
(nested_tbl_colm is nested table) 

FROM table_name t 
(table_name is the normal table whose one or more column is nested table here its nested_tbl_colm)  

WHERE t.tbl_colm= any input or conditions)

VALUES
(value to be inserted);

COMMIT;

将正常插入列的其余部分,并使用上面的代码插入到嵌套表中。 如果你不明白,请告诉我。