我在Sql Oracle存储过程中遇到问题

问题描述 投票:0回答:1

我正在尝试以下代码

        create or replace procedure sal2
        AS
        BEGIN
        select sal
        from emp
        END

并收到此错误

        Error at line 7: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the 
        following:
        ( begin case declare end exception 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
        5.  from emp
        6.  return 1
        7. END

我想做的是从emp表中获取sal列。我只是存储过程的新手,如果这是一个简单的错误,请不要立即投票。如果您回答,将不胜感激。

sql oracle stored-procedures plsql plsqldeveloper
1个回答
0
投票

以下代码有多个问题;

create or replace procedure sal2
 AS
 Lv_var number; -- added variable for holding select value
 BEGIN

 select sal
 Into lv_var -- into is needed in select
 from emp; -- you missed this semicolon
  -- you must use where clause as into variable can hold single value
  -- so you must restrict this query to return only 1 record. 

 END; -- you missed this semicolon
 /

干杯!

© www.soinside.com 2019 - 2024. All rights reserved.