简体   繁体   中英

Oracle DB - How to set IF statement in AND operator?

I want to set IF statement before execute AND operator.

For Example:

PROCEDURE STORE_SIGNLOOP_APPROVER
(
    userID     in  varchar2
    isManager  in varchar2
    result   out ref_cursor
) 
AS

BEGIN
    SELECT user_role
    FROM users
    WHERE user_id = userID
    AND **IF isManager = 'true'**  user_id IN (SELECT user id from managers)
END;

You could use:

select user_role
fron users
where user_id = userID
  AND (((user_id in (select user_id from managers) AND isManager = 'true'))
       OR isManager = 'false'
      );

Note: Instead of passing 'true/false' as string literal you could use '0/1' values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM