oracle plsql 存储过程 PLS-00103:遇到符号“SELECT”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12934680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:11:07  来源:igfitidea点击:

plsql stored procedure PLS-00103 :encounterd the symbol "SELECT"

oracleplsql

提问by danarj

I tried to created a stored procedure in Oracle 11G but i get this exception:

我试图在 Oracle 11G 中创建一个存储过程,但出现此异常:

Error(7,18): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:     ( - + case mod new not null <an identifier>    <a double-quoted delimited-identifier> <a bind variable>    continue avg count current exists max min prior sql stddev    sum variance execute forall merge time timestamp interval    date <a string literal with character set specification>    <a number> <a single-quoted SQL string> pipe    <an alternatively-quoted string literal with character set specification>    <an alternat
Error(9,65): PLS-00103: Encountered the symbol ")" 

this is my code:

这是我的代码:

create or replace
procedure PM_LOG_IN_SP(user_name_ in nvarchar2,  password_ in nvarchar2, res out int)
is
begin
    IF  user_name_ is not null and password_ is not null then

         res := (SELECT count(*)
          FROM HR.SYSTEM_USERS_TBL S
          WHERE S.USER_NAME = user_name_ AND S.PSWD = password_;)
    ELSE
          RES :=0;
    END IF;
end PM_LOG_IN_SP;

回答by Robert

If you want to set variable from a query, you should use select intoclause:

如果你想从查询中设置变量,你应该使用select into子句:

create or replace
procedure PM_LOG_IN_SP(user_name_ in nvarchar2,  
                       password_ in nvarchar2, 
                       res out int)
is
begin
    IF  user_name_ is not null and password_ is not null then

          SELECT count(*)
          into res 
          FROM HR.SYSTEM_USERS_TBL S
          WHERE S.USER_NAME = user_name_ AND S.PSWD = password_;
    ELSE
          RES :=0;
    END IF;
end PM_LOG_IN_SP;