What's the most efficient way to check if a record exists in Oracle?

前端 未结 10 2027
刺人心
刺人心 2020-12-23 03:10

A)

select decode(count(*), 0, \'N\', \'Y\') rec_exists
from (select \'X\'
      from dual
      where exists (select \'X\'
                    from sales
           


        
10条回答
  •  执笔经年
    2020-12-23 03:52

    here you can check only y , n if we need to select a name as well that whether this name exists or not.

    select name , decode(count(name),0, 'N', 'Y')
      from table
     group by name;
    

    Here when it is Y only then it will return output otherwise it will give null always. Whts ths way to get the records not existing with N like in output we will get Name , N. When name is not existing in table

提交回复
热议问题