Oracle sql return true if exists question

后端 未结 5 1272
清酒与你
清酒与你 2021-01-03 21:12

How do I check if a particular element exists in a table - how can I return true or false?

I have a table that has

  • user_id
  • user_password
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 21:47

    Oracle RDBMS does not have boolean data type, you can only use boolean variables in PL/SQL.

    If you simply want to return strings 'TRUE' and 'FALSE' you can do this..

    SELECT 'TRUE'  FROM DUAL WHERE EXISTS (SELECT 'x' FROM  table WHERE user_id = 'id')
    UNION
    SELECT 'FALSE' FROM DUAL WHERE NOT EXISTS (SELECT 'x' FROM  table WHERE user_id = 'id')
    

    I like @DCookie's query though.

提交回复
热议问题