我有下面的PLSQL程序,使用减号运算符比较两个表并存储在VARCHAR TYPE中。该过程成功编译,但是执行时出现以下错误。表中的所有类型均为varchar2
create or replace procedure compare_tables(t1 in varchar2, t2 in varchar2)
is
v_qry varchar2(10000);
TYPE T_MY_LIST IS TABLE OF VARCHAR2(100);
v_cmp_cols T_MY_LIST; -- list of distinct
begin
FOR i in 1..1000
loop
v_qry:= 'SELECT JOB_NAME' ||','|| 'TYPE_OF_BATCH FROM '
|| t1
|| ' MINUS SELECT JOB_NAME' ||','|| 'TYPE_OF_BATCH FROM '
|| t2 ;
DBMS_Output.PUT_LINE (v_qry);
execute immediate v_qry bulk collect into v_cmp_cols;
FOR j in 1..v_cmp_cols.count loop
DBMS_Output.PUT_LINE (v_cmp_cols(j));
end loop;
end loop;
end compare_tables;
begin
compare_tables('a','b');
end;
enter Error report -
ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at "STSC.COMPARE_TABLES", line 20
ORA-06512: at line 2
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:code here
答案 0 :(得分:4)
您的查询正在选择两列,但是您正试图将其批量收集为标量数据类型的单个集合。
要么声明两个集合变量:
insert into Search_file(
type,
fileName,
document_title_id
)values
(value1,value2,value3),
(value1,value2,value3)
near "values": syntax error:insert into Search_file(
type,
fileName,
document_title_id
)values
,然后同时使用两者:
TYPE T_MY_LIST IS TABLE OF VARCHAR2(100);
v_cmp_job_name T_MY_LIST;
v_cmp_type_of_batch T_MY_LIST;
或声明记录类型和这些记录的集合
execute immediate v_qry bulk collect into v_cmp_job_name, v_cmp_type_of_batch;
FOR j in 1..v_cmp_job_name.count loop
DBMS_Output.PUT_LINE (v_cmp_job_name(j) ||','|| v_cmp_type_of_batch(j));
end loop;
并使用一个集合,请参考其字段:
TYPE T_MY_REC IS RECORD (
job_name varchar2(100),
type_of_batch varchar2(100)
);
TYPE T_MY_LIST IS TABLE OF T_MY_REC;
v_cmp_cols T_MY_LIST;