fetch only first row from oracle - is it faster?

Posted by john on Stack Overflow See other posts from Stack Overflow or by john
Published on 2010-06-13T13:39:59Z Indexed on 2010/06/13 13:42 UTC
Read the original article Hit count: 259

Filed under:
|

My main goal with this question is optimization and faster run time.

After doing lot of processing in the Stored Proc I finally return a count like below:

          OPEN cv_1 FOR
             SELECT COUNT(*) num_of_members
               FROM HOUSEHOLD_MEMBER a,
                    HOUSEHOLD b
                WHERE RTRIM(LTRIM(a.mbr_last_name)) LIKE v_MBR_LAST_NAME || '%'
                        AND a.number = '01'
                        AND a.code = v_CODE
                        AND a.ssn_head = v_SSN_HEAD
                        AND TO_CHAR( a.mbr_dob, 'MM/DD/YYYY') = v_DOB;

But in my code that is calling the SP does not need the actual count. It just cares that count is greater than 1.

Question:

  1. How can I change this to return just 1 or 0. 1 when count is > 0 and 0 when count > 1.
  2. Will it be faster to do this rather than returning the whole count?

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about plsql