简体   繁体   English

PL/SQL 过程未编译

[英]PL/SQL procedure not compiling

I have a PL/SQL procedure that is not compiling.我有一个未编译的 PL/SQL 过程。 The errors are:错误是:

  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 . Error(8,1): PLS-00428: an INTO clause is expected in this SELECT statement

My code:我的代码:

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

I have googled an online syntax checker and it says on the first line there is an error.我用谷歌搜索了一个在线语法检查器,它在第一行说有一个错误。 But WHERE??.但是哪里??。 It seems to be correct.这似乎是正确的。 I have googled the syntax of declaring a procedure and I have cross-checked many times.我已经搜索了声明过程的语法,并且我已经交叉检查了很多次。 It must be something simple that I am overlooking...我忽略的一定很简单...

in a PLSQL code, you need a placeholder to keep results of a SELECT query.在 PLSQL 代码中,您需要一个占位符来保存 SELECT 查询的结果。 Since PLSQL engine is expecting INTO clause within SELECT statement.由于 PLSQL 引擎在 SELECT 语句中期待 INTO 子句。

To begin with, you can select a set of columns and assign their values to local variables.首先,您可以 select 一组列并将它们的值分配给局部变量。

Your code should be like this -你的代码应该是这样的 -

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

Note - you need to replace column1 and column2 with actual column names before running this code at your end.注意 - 在最后运行此代码之前,您需要将 column1 和 column2 替换为实际的列名。

If you want the results to get displayed on the caller of the procedure, then you would define an out parameter and print the records outside of the procedure如果您希望结果显示在过程的调用者上,那么您将定义一个 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 has support for implict return results Oracle 12c 支持隐式返回结果

Have a look at this link https://oracle-base.com/articles/12c/implicit-statement-results-12cr1看看这个链接https://oracle-base.com/articles/12c/implicit-statement-results-12cr1

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

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