Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Comparison of EXIST Performance with Count

Bollineni86Feb 11 2016 — edited Feb 11 2016

Hi ALL,

TRIM(ename)=

  CASE

    WHEN(SELECT COUNT(e2.ename)

      FROM emp e2

      WHERE e2.empno = e.empno

      ) > 0

    THEN e2.ename

    ELSE 'ALL'

  END

TRIM(ename)=

  CASE

    WHEN exists (SELECT *

      FROM emp e2

      WHERE e2.empno = e.empno

      )

    THEN e2.ename

    ELSE 'ALL'

  END

In above two scenarios which one is best to use performance wise. I have tested exists condition, it tooks less time rather than Count() function.

but in some articles wrote that exist will do full table scan. So i am in confused which one is best..?

Suggestions please...

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 10 2016
Added on Feb 11 2016
6 comments
3,367 views