首页 > 解决方案 > 如何将 Oracle 集合数据插入表的 CLOB 列

问题描述

我在集合变量中有记录。O 想将所有记录插入到表的 CLOB 列中。

    set serveroutput on;
declare
    type ROW_DATA is table of varchar2(256) ;
    ROW_D ROW_DATA;
begin
    with DIFF_TAB_DATA as
    (
    select SOME_COLUMN from SOME_TABLE1
    union all
    select SOME_COLUMN from SOME_TABLE2
    union all
    select SOME_COLUMN from SOME_TABLE3
    union all
    select SOME_COLUMN from SOME_TABLE4
    union all
    select SOME_COLUMN from SOME_TABLE5
    )
    select SOME_COLUMN bulk collect into ROW_D from DIFF_TAB_DATA;
    insert into CLOB_TAB values(ROW_D);
end;

但是我得到了本地集合变量不能在插入语句中使用的错误。

标签: sqloracleplsqltypes

解决方案


是的,这是一个不匹配本地集合类型不能替换为当前值的数据类型,它们是完全不相关的而是将集合与索引集一起调用以提取存储在其中的值。为了执行此操作,只需更换

INSERT INTO clob_tab VALUES(row_d);

FORALL indx IN 1 .. row_d.COUNT
INSERT INTO clob_tab VALUES(row_d(indx));

推荐阅读