繁体   English   中英

PL/SQL 过程未编译

[英]PL/SQL procedure not compiling

我有一个未编译的 PL/SQL 过程。 错误是:

  1. 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 <an identifier> <a double-quoted delimited-identifier> <a bind variable> << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge The symbol "INTO" was ignored.

  2. 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;
/

我用谷歌搜索了一个在线语法检查器,它在第一行说有一个错误。 但是哪里??。 这似乎是正确的。 我已经搜索了声明过程的语法,并且我已经交叉检查了很多次。 我忽略的一定很简单...

在 PLSQL 代码中,您需要一个占位符来保存 SELECT 查询的结果。 由于 PLSQL 引擎在 SELECT 语句中期待 INTO 子句。

首先,您可以 select 一组列并将它们的值分配给局部变量。

你的代码应该是这样的 -

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 替换为实际的列名。

如果您希望结果显示在过程的调用者上,那么您将定义一个 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;

Oracle 12c 支持隐式返回结果

看看这个链接https://oracle-base.com/articles/12c/implicit-statement-results-12cr1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM