SQL*Plus Oracle DB - 使用布尔输出参数执行过程
SQL*Plus Oracle DB - Executing procedure with boolean output parameter
我正在尝试使用来自 SQL*Plus 的一个输入 (varchar) 和一个输出 (boolean) 参数来执行一个存储过程。
我有:
ALTER session SET nls_language='AMERICAN';
set serveroutput on;
declare bResult boolean;
exec procedureName('TEST', bResult);
/
exit;
我得到的:
PLS-00103: Encountered the symbol 'end-of-file' when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
我正在从批处理脚本调用 SQL*Plus,我需要调用此过程并根据过程的结果 (bResult) 继续批处理脚本。
在 SQL Developer 中,我可以使用以下命令成功执行程序和 return 输出(在 SQL*Plus 中不起作用):
ALTER session SET nls_language='AMERICAN';
set serveroutput on;
declare bResult boolean;
begin
procedureName('TEST', bResult);
dbms_output.put_line(sys.diutil.bool_to_int(bResult));
end;
我该怎么做才能让它与 SQL*Plus 一起使用?
以下作品在SQL*Plus(不要忘记结尾/
):
$ sqlplus system/oracle @tproc
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jun 18 16:31:55 2020
Version 19.5.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Thu Jun 18 2020 16:31:27 +02:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.5.0.0.0
Session altered.
SQL> --
SQL> create or replace procedure procedurename(p1 in varchar2, p2 out boolean)
2 as
3 begin
4 p2 := true;
5 end;
6 /
Procedure created.
SQL> show errors
No errors.
SQL>
SQL> ALTER session SET nls_language='AMERICAN';
Session altered.
SQL> set serveroutput on;
SQL> declare bResult boolean;
2 begin
3 procedureName('TEST', bResult);
4 dbms_output.put_line(sys.diutil.bool_to_int(bResult));
5 end;
6 /
1
PL/SQL procedure successfully completed.
SQL>
实际上,您是使用declare
声明变量,您需要使用匿名块,如下所示:
SQL>
SQL> ALTER session SET nls_language='AMERICAN';
Session altered.
SQL> set serveroutput on;
SQL> declare bResult boolean;
2 begin -- this is needed
3 proc('TEST', bResult); -- remove exec
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> exit;
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
C:\Users\tejas.hingu>
我正在尝试使用来自 SQL*Plus 的一个输入 (varchar) 和一个输出 (boolean) 参数来执行一个存储过程。
我有:
ALTER session SET nls_language='AMERICAN';
set serveroutput on;
declare bResult boolean;
exec procedureName('TEST', bResult);
/
exit;
我得到的:
PLS-00103: Encountered the symbol 'end-of-file' when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
我正在从批处理脚本调用 SQL*Plus,我需要调用此过程并根据过程的结果 (bResult) 继续批处理脚本。
在 SQL Developer 中,我可以使用以下命令成功执行程序和 return 输出(在 SQL*Plus 中不起作用):
ALTER session SET nls_language='AMERICAN';
set serveroutput on;
declare bResult boolean;
begin
procedureName('TEST', bResult);
dbms_output.put_line(sys.diutil.bool_to_int(bResult));
end;
我该怎么做才能让它与 SQL*Plus 一起使用?
以下作品在SQL*Plus(不要忘记结尾/
):
$ sqlplus system/oracle @tproc
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jun 18 16:31:55 2020
Version 19.5.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Thu Jun 18 2020 16:31:27 +02:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.5.0.0.0
Session altered.
SQL> --
SQL> create or replace procedure procedurename(p1 in varchar2, p2 out boolean)
2 as
3 begin
4 p2 := true;
5 end;
6 /
Procedure created.
SQL> show errors
No errors.
SQL>
SQL> ALTER session SET nls_language='AMERICAN';
Session altered.
SQL> set serveroutput on;
SQL> declare bResult boolean;
2 begin
3 procedureName('TEST', bResult);
4 dbms_output.put_line(sys.diutil.bool_to_int(bResult));
5 end;
6 /
1
PL/SQL procedure successfully completed.
SQL>
实际上,您是使用declare
声明变量,您需要使用匿名块,如下所示:
SQL>
SQL> ALTER session SET nls_language='AMERICAN';
Session altered.
SQL> set serveroutput on;
SQL> declare bResult boolean;
2 begin -- this is needed
3 proc('TEST', bResult); -- remove exec
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> exit;
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
C:\Users\tejas.hingu>