(更新 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;
/
并在蟾蜍中运行它,使用以下脚本:
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#调用时收到相同的错误消息
你有 ro 删除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
类型会更好。
如前面的回答所述,调用过程本身有几个错误。
用于调用该过程的代码应如下所示:
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;
/
干杯!!