我有另一個線程來解決不同的問題,現在我卡在另一個,看似簡單,錯誤。我的鱈魚如下: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