我有另一个线程来解决不同的问题,现在我卡在另一个,看似简单,错误。我的鳕鱼如下:PL/SQL - 连接时出现此错误:PLS-00306:调用'||'时参数的数量或类型错误
declare
update_count integer := 0;
prjt_name varchar2(100) not null := '01213264B';
cursor my_cur is (select table_name from [email protected]_pos15 where column_name = 'PROJECT_ID' and owner = 'SANDBOX');
tableName my_cur%rowtype;
begin
for tableName in my_cur
loop
update_count := 0;
Execute immediate
'select count(t.project_id) as "CNT" from sandbox.'
|| tableName
|| '@adhoc_pos15 t'
|| 'where t.project_id = (select project_id from [email protected]_pos15 where project_name = upper('
|| prjt_name
|| '))'
into update_count;
if update_count = 0 then
execute immediate
'DELETE FROM my_cur where table_name = '
|| tableName;
end if;
end loop;
end;
我的错误信息是
ORA-06550: line 11, column 8:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: line 10, column 6:
PL/SQL: Statement ignored
ORA-06550: line 20, column 8:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: line 19, column 6:
PL/SQL: Statement ignored
如果你有兴趣。我会通过一个链接指出我以前遇到的错误。你可以看到代码最初的样子。
编辑1:每瓦利的建议。我已更新我的编码,并在第15行获取错误缺失表达。
declare
query varchar2(10000);
update_count integer := 0;
prjt_name varchar2(100) := '01213264B';
cursor my_cur is (select table_name from [email protected] column_name = 'PROJECT_ID' and owner = 'SANDBOX');
tableName varchar2(100);
begin
open my_cur;
loop
fetch my_cur into tableName;
exit when my_cur%NOTFOUND;
update_count := 0;
execute immediate
'select count(project_id) as "CNT" from sandbox.' || tableName || '@db2 '
|| ' where project_id = (select project_id from [email protected] where project_name = ''' || prjt_name || ''') '
into update_count;
if update_count > 0 then
dbms_output.put_line (tableName);
end if;
end loop;
close my_cur;
end;
我缺少一个“=”符号。现在运行。我收到了几条比错误信息要多的结果
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04040: file ext_qsp_benefit.dat in DATA_DIR not found
ORA-02063: preceding 3 lines from ADHOC_POS15
ORA-06512: at line 13
最终编辑:成功!显然我无法查询某些表格。所以我只是把这些表拿出来。
最后的编码是:
declare
query varchar2(10000);
update_count integer := 0;
prjt_name varchar2(100) := '01213264B';
cursor my_cur is (select table_name from [email protected] where column_name = 'PROJECT_ID' and owner = 'SANDBOX' and table_name in ('X'));
tableName varchar2(100);
begin
open my_cur;
loop
fetch my_cur into tableName;
exit when my_cur%NOTFOUND;
update_count := 0;
execute immediate
'select count(project_id) as "CNT" from sandbox.' || tableName || '@db2 '
|| ' where project_id = (select project_id from [email protected] where project_name = ''' || prjt_name || ''') '
into update_count;
if update_count > 0 then
dbms_output.put_line (tableName);
end if;
end loop;
close my_cur;
end;
此不做正是我想要的。它将结果发送到dbms_output。但这是一个开始!谢谢大家的帮助!
在连接显示的“进入”行后,我仍然收到相同的错误消息。 – tparker
为什么在声明部分使用not null。这在plsql blok中不起作用。 – Valli
我需要这个子查询,因为prjct_name是由用户创建和提供的。但是我们的系统把这个名字变成了一个数字,这个数字就是用来识别变化的。我不能依赖最终用户知道如何计算他们的项目编号。 – tparker