pl/sql过程未编译

oxiaedzo  于 2021-07-29  发布在  Java
关注(0)|答案(2)|浏览(365)

我有一个没有编译的pl/sql过程。错误包括:
Error(3,7): PLS-00103: Encountered the symbol "INTO" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge The symbol "INTO" was ignored. Error(8,1): PLS-00428: an INTO clause is expected in this SELECT statement .
我的代码:

CREATE OR REPLACE PROCEDURE findvisitsandlaborcosts
as
begin
select * from SI.customer;
end;
/

我在google上搜索了一个在线语法检查器,它在第一行显示有一个错误。但是在哪里?!?这似乎是正确的。我在google上搜索了声明一个过程的语法,并且反复检查了很多次。一定是我忽略了一些简单的事情。。。

0g0grzrc

0g0grzrc1#

在plsql代码中,您需要一个占位符来保存select查询的结果。因为plsql引擎在select语句中需要into子句。
首先,可以选择一组列并将其值赋给局部变量。
你的代码应该是这样的-

CREATE OR REPLACE PROCEDURE findvisitsandlaborcosts
as
v_column1 SI.customer.column1%type;
v_column2 SI.customer.column2%type;
begin
select column1, column2 into v_column1, v_column2 from SI.customer;
end;
/

注意-在运行此代码之前,需要用实际的列名替换column1和column2。

w41d8nur

w41d8nur2#

如果希望结果显示在过程的调用者上,那么可以定义out参数并打印过程外部的记录

CREATE OR REPLACE PROCEDURE findvisitsandlaborcosts(x out sys_refcursor)
as
begin
open x for 
select * from dual;
end;
/

--Note this block of code needs to be run in sqlci or sqldeveloper
define m ref cursor;

exec findvisitsandlaborcosts(:x);

print x;

oracle12c支持隐式返回结果
看看这个链接https://oracle-base.com/articles/12c/implicit-statement-results-12cr1

相关问题