如果存在问题,Oracle sql返回true
问题描述:
如何检查表中是否存在特定元素 - 如何返回true或false?
How do I check if a particular element exists in a table - how can I return true or false?
我有一个表
- user_id
- user_password
- user_secretQ
口头上,我想这样做:如果 user_id中存在特定的
列,然后返回true - 否则返回false。 user_id
Verbally, I want to do this: If a particular user_id
exists in the user_id
column, then return true -- otherwise return false.
答
Oracle中没有布尔类型SQL。您将需要返回1或0或其他一些并相应地采取行动:
There is no Boolean type in Oracle SQL. You will need to return a 1 or 0, or some such and act accordingly:
SELECT CASE WHEN MAX(user_id) IS NULL THEN 'NO' ELSE 'YES' END User_exists
FROM user_id_table
WHERE user_id = 'some_user';