如何在sqlplus中执行PL/SQL Oracle?
How to execute PL/SQL Oracle in sqlplus?
我在oracle中有sp。我的SP如下图
create or replace
PROCEDURE GETMONITORING
(
v_namabarang in varchar2 default null,
v_JenisLayanan in varchar2 default null,
cv_1 IN OUT SYS_REFCURSOR
)
AS
v_where VARCHAR2(200);
v_Select VARCHAR2(200);
v_from VARCHAR2(200);
v_final VARCHAR2(200);
v_result VARCHAR2(200);
BEGIN
v_Select:='select * ';
v_from :='from permohonan ';
v_where :='where sysdate=sysdate ';
IF nvl(length(v_namabarang),0) <> 0 then
v_Where := v_Where || ' AND namabarang like ''' || v_namabarang|| '%'' ';
end if;
IF nvl(length(v_jenislayanan),0) <> 0 then
v_Where := v_Where || ' AND jenislayanan like ''' || v_jenislayanan || '%'' ';
end if;
v_final :=v_select|| v_from|| v_where;
dbms_output.put_line(v_result);
END;
我试图通过
在sqlplus中执行
SQL> var r refcursor;
SQL> exec getmonitoring('AC','1',:r);
SQL>print :r;
结果是"ORA-24338":语句句柄未执行
那么,我如何在 sqlplus 中执行我的 SP?谢谢
从您从未 OPEN CURSOR 而是引用 [ 的事实可以明显看出错误=44=] 作为 OUT 参数。
ORA-24338: statement handle not executed
Cause: A fetch or describe was attempted before executing a statement handle.
Action: Execute a
statement and then fetch or describe the data.
您需要使用 OPEN cursor FOR... 语句:
v_final :=v_select|| v_from|| v_where;
-- open the cursor
OPEN cv_1 FOR v_final;
附带说明一下,在 编译 PL/SQL 到 SQL*Plus 时,如果您看到错误,您应该始终使用 SHOW ERRORS 来查看完整的错误堆栈。
例如,
SQL> create or replace procedure p
2 as
3 begin
4 null
5 end;
6 /
Warning: Procedure created with compilation errors.
SQL> show errors
Errors for PROCEDURE P:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/1 PLS-00103: Encountered the symbol "END" when expecting one of the
following:
;
The symbol ";" was substituted for "END" to continue.
所以,现在您知道确切的行号和错误消息,这将帮助您调试和修复错误。
我在oracle中有sp。我的SP如下图
create or replace
PROCEDURE GETMONITORING
(
v_namabarang in varchar2 default null,
v_JenisLayanan in varchar2 default null,
cv_1 IN OUT SYS_REFCURSOR
)
AS
v_where VARCHAR2(200);
v_Select VARCHAR2(200);
v_from VARCHAR2(200);
v_final VARCHAR2(200);
v_result VARCHAR2(200);
BEGIN
v_Select:='select * ';
v_from :='from permohonan ';
v_where :='where sysdate=sysdate ';
IF nvl(length(v_namabarang),0) <> 0 then
v_Where := v_Where || ' AND namabarang like ''' || v_namabarang|| '%'' ';
end if;
IF nvl(length(v_jenislayanan),0) <> 0 then
v_Where := v_Where || ' AND jenislayanan like ''' || v_jenislayanan || '%'' ';
end if;
v_final :=v_select|| v_from|| v_where;
dbms_output.put_line(v_result);
END;
我试图通过
在sqlplus中执行SQL> var r refcursor;
SQL> exec getmonitoring('AC','1',:r);
SQL>print :r;
结果是"ORA-24338":语句句柄未执行
那么,我如何在 sqlplus 中执行我的 SP?谢谢
从您从未 OPEN CURSOR 而是引用 [ 的事实可以明显看出错误=44=] 作为 OUT 参数。
ORA-24338: statement handle not executed
Cause: A fetch or describe was attempted before executing a statement handle.
Action: Execute a statement and then fetch or describe the data.
您需要使用 OPEN cursor FOR... 语句:
v_final :=v_select|| v_from|| v_where;
-- open the cursor
OPEN cv_1 FOR v_final;
附带说明一下,在 编译 PL/SQL 到 SQL*Plus 时,如果您看到错误,您应该始终使用 SHOW ERRORS 来查看完整的错误堆栈。
例如,
SQL> create or replace procedure p
2 as
3 begin
4 null
5 end;
6 /
Warning: Procedure created with compilation errors.
SQL> show errors
Errors for PROCEDURE P:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/1 PLS-00103: Encountered the symbol "END" when expecting one of the
following:
;
The symbol ";" was substituted for "END" to continue.
所以,现在您知道确切的行号和错误消息,这将帮助您调试和修复错误。