2017-10-20 123 views
0

我有另一个线程来解决不同的问题,现在我卡在另一个,看似简单,错误。我的鳕鱼如下: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 

如果你有兴趣。我会通过一个链接指出我以前遇到的错误。你可以看到代码最初的样子。

Encountered 'Loop' Error

编辑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。但这是一个开始!谢谢大家的帮助!

回答

0

一两件事,看起来错误是prjt_name是一个字符串,但你把它作为你的查询号码。因此,这里就是我会改变:

|| 'where t.project_id = (select project_id from [email protected]_pos15 where project_name = upper(''' 
    || prjt_name 
    || '''))' 

这基本上增加了' '周围的字符串值。

然后,由于您从执行中得到2个错误,所以必须存在tableName的问题。我宁愿使用隐式游标,但你应该尝试访问光标的内容,如下图所示:

'select count(t.project_id) as "CNT" from sandbox.' 
    || tableName.table_name 
    || '@adhoc_pos15 t' 
    || 'where t.project_id = (select project_id from [email protected]_pos15 where project_name = upper(''' 
    || prjt_name 
    || '''))' 

而且你必须删除delete你从你的光标做......这看起来完全错误的。循环只是移动到下一个记录

希望这会有所帮助。

0
declare 
     update_count integer := 0; 
     prjt_name varchar2(100) := '01213264B'; 
     tablename varchar2(100); 

     cursor my_cur is 
      select table_name 
       from [email protected]_pos15 
       where column_name = 'PROJECT_ID' and owner = 'SANDBOX'; 
    begin 
     OPEN my_cur; 
     LOOP 
     FETCH my_cur into tableName; 
      EXIT WHEN my_cur%NOTFOUND; 
      update_count := 0; 
      Execute immediate 
       'select count(t.project_id) as "CNT" from sandbox.' 
       || tableName 
       || '@adhoc_pos15 t' 
       || ' where t.project_id in (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; 
    CLOSE my_cur; 
    end; 

您最后错过了一个连接。一些语法错误太多

注: -

为什么你在这里需要一个子查询?

where t.project_id in (select project_id from [email protected]_pos15 where project_name = upper(' 
      || prjt_name 

可以替代由

where t.project_name = prjt_name 
+0

在连接显示的“进入”行后,我仍然收到相同的错误消息。 – tparker

+0

为什么在声明部分使用not null。这在plsql blok中不起作用。 – Valli

+0

我需要这个子查询,因为prjct_name是由用户创建和提供的。但是我们的系统把这个名字变成了一个数字,这个数字就是用来识别变化的。我不能依赖最终用户知道如何计算他们的项目编号。 – tparker

相关问题