【问题标题】:Oracle stored procedure runtime error with pls 00103Oracle 存储过程运行时错误与 pls 00103
【发布时间】:2019-07-22 10:00:00
【问题描述】:

(2019/07/23 更新)调用过程的新方法

SET SERVEROUTPUT ON
declare
  variable res sys_refcursor;
begin
  my_schema.SP_READ_MEMBER('11223344', '1970/01/01', res);
EXCEPTION
  WHEN OTHERS
  THEN DBMS_OUTPUT.put_line ('ERROR ' || SQLERRM);
end;
/

结果

Error at line 2
ORA-06550: line 2, column 16:
PLS-00103: Encountered the symbol "SYS_REFCURSOR" when expecting one of the following:

   := . ( @ % ; not null range default character
The symbol ":=" was substituted for "SYS_REFCURSOR" to continue.

(原帖)

我不太擅长 Oracle 的存储过程,所以这个错误让我很困惑。在这个网站上阅读了 10 个关于 PLS-00103 的主题。但他们似乎都没有帮助解决我的错误。

这是我的存储过程

create or replace procedure my_schema.SP_READ_MEMBER(keywordP in varchar2, birthdayP in varchar2, resultP out sys_refcursor)
is
v_prg_name varchar2(20) := 'SP_READ_MEMBER';
sys_sql    varchar2(1000);

begin
  Insertlog(SYSDATE, v_prg_name, '1.0 Start');
  sys_sql :=  sys_sql || 'select a.no, a.name, a.id_no, to_char(a.birthday, ''yyyy/MM/dd'') as birthday, ''REGISTERED'' as type, email, mobile from rep  a where 1=1 ';
  if keywordP is not null then
    sys_sql :=  sys_sql || ' and (a.no=''' || keywordP || ''' or a.name=''' || keywordP || ''' or a.id_no=''' || keywordP || ''') ';
  end if;
  if birthdayP is not null then
    sys_sql :=  sys_sql || ' and a.birthday=to_date(''' || birthdayP || ''', ''yyyy/MM/dd'') ';
  end if;

  open resultP for sys_sql;
  Insertlog(SYSDATE, v_prg_name, '2.0 Finished w/o error');

  exception
  when others then
  declare
    error_time VARCHAR2(30) := RTRIM(TO_CHAR(SYSDATE, 'YYYY/MM/DD, HH24:MI:SS'));
    error_code NUMBER := SQLCODE;
    error_msg  VARCHAR2(300) := SQLERRM;
  begin
    rollback;
    DBMS_OUTPUT.PUT_LINE(error_time || ',' || TO_CHAR(error_code) || ',' || error_msg);
    Insertlog(SYSDATE, v_prg_name,  error_msg || ', 3.0 ERROR, sql:' || sys_sql);
  end;
end;
/

并在 toad 中运行它,使用以下脚本:

SET SERVEROUTPUT ON
declare
  res varchar2(1000);
begin
  call my_schema.SP_READ_MEMBER('11223344', '1970/01/01', res);
EXCEPTION
  WHEN OTHERS
  THEN DBMS_OUTPUT.put_line ('ERROR ' || SQLERRM);
end;
/

这个错误信息真的让我很困惑......

Error at line 2
ORA-06550: line 4, column 8:
PLS-00103: Encountered the symbol "my_schema" when expecting one of the following:

   := . ( @ % ;
The symbol ":=" was substituted for "my_schema" to continue.

现在卡在这里,请给一些建议,真的需要这个......

PS: 从 c# 调用时得到相同的错误消息

【问题讨论】:

  • 我不太清楚;您正在创建一个过程my_schema.SP_READ_MEMBER,并运行forest.SP_READ_REP;是错字吗?如果是这样,您能否发布您的确切代码?
  • 更改create or replace procedure my_schema.SP_READ_MEMBER --> create or replace procedure forest.SP_READ_MEMBER
  • 哎呀,抱歉,这是类型错误,我会编辑我的问题...但确实存在错误,请给我一些建议。
  • 代码已满,由于办公室政策,我不得不隐藏架构和过程名称...

标签: oracle stored-procedures pls-00103


【解决方案1】:

您可以删除call;例如:

SQL> begin
  2      call testProc;
  3  end;
  4  /
    call testProc;
         *
ERROR at line 2:
ORA-06550: line 2, column 10:
PLS-00103: Encountered the symbol "TESTPROC" when expecting one of the
following:
:= . ( @ % ;
The symbol ":=" was substituted for "TESTPROC" to continue.


SQL> begin
  2      testProc;
  3  end;
  4  /

PL/SQL procedure successfully completed.

另外,请注意您的过程有一个sys_refcursor out 参数,但您通过传递varchar2 来调用它。

顺便说一句,使用varchar2 处理日期不是一个好主意; date 类型会更好。

【讨论】:

    【解决方案2】:

    前面的回答提到过,调用过程本身有几个错误。

    调用该过程的代码应如下所示:

    SET SERVEROUTPUT ON
    declare
      res SYS_REFCURSOR; -- Changed data type of this variable
    begin
      my_schema.SP_READ_MEMBER('11223344', '1970/01/01', res); -- removed 'call'
    EXCEPTION
      WHEN OTHERS
      THEN DBMS_OUTPUT.put_line ('ERROR ' || SQLERRM);
    end;
    /
    

    干杯!!

    【讨论】:

    • 您好,我试过了,但还是有错误。更新了我的问题,您能提供更多建议吗?
    • 这个匿名块遇到了什么错误?
    • 您好,由于消息太多,我将其更新到我原来的问题之上。
    猜你喜欢
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多