select 查询的存储过程未提供输出
stored procedure for select query not giving output
我正在使用 sqlplus
并有一个名为 users
的 table,我希望借助 oracle
中的 stored procedure
从中检索所有值].这是我正在尝试做的 -
create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users
end;
/
之后当我点击 return
时,出现以下错误 -
Warning: Procedure created with compilation errors.
为什么会这样?我如何获得所需的输出?非常感谢帮助!
要查看编译错误,请使用 the show errors
SQL*Plus command(也适用于 SQL Developer),或查询适用于任何客户端的 user_errors
视图。您还可以查询 all_errors
以查看不在您的架构中的对象的问题。
但是您只是在 select:
之后少了一个分号
create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users;
end;
/
您需要一个绑定变量才能在 SQL*Plus 中看到输出,例如:
variable rc refcursor;
exec getall(:rc);
print rc
注意过程调用中 rc
之前的冒号,这表明它是一个绑定变量引用。 exec
是一个 shorthand 匿名块。
您可能会发现拥有一个 returns 引用游标或流水线函数的函数更简单;当然也可以直接查询 table。
我正在使用 sqlplus
并有一个名为 users
的 table,我希望借助 oracle
中的 stored procedure
从中检索所有值].这是我正在尝试做的 -
create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users
end;
/
之后当我点击 return
时,出现以下错误 -
Warning: Procedure created with compilation errors.
为什么会这样?我如何获得所需的输出?非常感谢帮助!
要查看编译错误,请使用 the show errors
SQL*Plus command(也适用于 SQL Developer),或查询适用于任何客户端的 user_errors
视图。您还可以查询 all_errors
以查看不在您的架构中的对象的问题。
但是您只是在 select:
之后少了一个分号create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users;
end;
/
您需要一个绑定变量才能在 SQL*Plus 中看到输出,例如:
variable rc refcursor;
exec getall(:rc);
print rc
注意过程调用中 rc
之前的冒号,这表明它是一个绑定变量引用。 exec
是一个 shorthand 匿名块。
您可能会发现拥有一个 returns 引用游标或流水线函数的函数更简单;当然也可以直接查询 table。