在IF语句中使用SELECT

时间:2015-01-03 14:15:56

标签: oracle if-statement

我想要一个这样的查询:

 if ((select closedatetime from tbl_eventschedularmaster where eventid=p_EventId)> sysdate)
 then
     update tbL_ANSWERMASTER set AnsText=p_AnsText
      where AnsId=p_checkduplicate RETURNING AnsId INTO p_ReturnVal;
else 
      RETURNING 0 INTO p_ReturnVal;
 end if

但它不起作用

1 个答案:

答案 0 :(得分:1)

您需要重新编写

select closedatetime
  into dtClosedDateTime
  from tbl_eventschedularmaster
  where eventid = p_EventId;

if dtClosedDateTime > sysdate then
  update tbL_ANSWERMASTER
    set AnsText=p_AnsText
    where AnsId=p_checkduplicate
    RETURNING AnsId INTO p_ReturnVal;
else 
  p_ReturnVal := 0;
end if;

分享并享受。