[英]PL/SQL procedure not compiling
我有一個未編譯的 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 <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.
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.