Oracle - IF 子句中的子查询

伊姆兰·赫曼尼

我有以下代码:

if USER IN (SELECT user_id from user_maint where roll = 12) THEN
        p_status := 'W';

ELSE 
        p_status := 'A';
END IF;

它给出了错误: Error(332,16): PLS-00405: subquery not allowed in this context

如何在 IF 子句中进行子查询?

小脚怪

Select首先,在if下一步中使用

declare
  l_user_id user_maint.user_id%type;
  p_status  varchar2(1);
begin
  select user_id
  into l_user_id
  from user_maint
  where roll = 12;

  if l_user_id = user then
     p_status := 'W';
  else
     p_status := 'A';
  end if;
end;
/

虽然,一个更简单的选择是

select case when user_id = user then 'W'
            else 'A'
       end
into p_status
from user_maint
where roll = 12;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章