【问题标题】:PL/SQL procedure not compilingPL/SQL 过程未编译
【发布时间】:2020-10-23 16:20:06
【问题描述】:

我有一个未编译的 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;
/

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

【问题讨论】:

  • 您需要将结果保存在某处。存储过程不能只运行查询。结果无处可放。
  • 您从哪里得到PLS-00103:遇到符号“INTO”?我没有看到任何 into 关键字。

标签: sql plsql procedure


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      相关资源
      最近更新 更多