Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8020239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:37:55+00:00 2026-06-04T21:37:55+00:00

I have a following stored procedure in which I have used a cursor. Depending

  • 0

I have a following stored procedure in which I have used a cursor. Depending on whether the cursor return any records or not I need to do some processing.

But I am not sure how to check if the cursor return any records.

CREATE OR REPLACE PROCEDURE SP_EMPLOYEE_LOOKUP_BY_EMP_ID
(
      IN_USER_ID IN NUMBER, 
      IN_EMPLOYEE_ID NUMBER,
      IN_HC_AS_ON_DATE VARCHAR2,
      emp_cursor OUT SYS_REFCURSOR
) 
IS 

 CURSOR employees IS 
    SELECT  * FROM EMPLOYEE e; 

BEGIN    

if(record exist ) then 

 FOR employee IN employees
  LOOP  

        // do something  

  END LOOP; 
else if employees is empty then 
     // do something else 

END;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:37:56+00:00Added an answer on June 4, 2026 at 9:37 pm

    It’s not possible to check if the cursor returns records without opening it.
    (see here)
    So you can either have some fast query just to see if there are records (using count for example),

    Or, you can do it like this:

    CREATE OR REPLACE PROCEDURE SP_EMPLOYEE_LOOKUP_BY_EMP_ID
    (
          IN_USER_ID IN NUMBER, 
          IN_EMPLOYEE_ID NUMBER,
          IN_HC_AS_ON_DATE VARCHAR2,
          emp_cursor OUT SYS_REFCURSOR
    ) 
    IS 
    
     is_found_rec boolean := false;    
    
     CURSOR employees IS 
        SELECT  * FROM EMPLOYEE e; 
    
    BEGIN    
    
     FOR employee IN employees
      LOOP  
    
        is_found_rec := true;
    
            // do something  
    
      END LOOP; 
    
     if not is_found_rec then 
         // do something else 
     end if;
    
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following stored procedure which will generate mon to sun and then
I have a mysql stored procedure which is giving me the following error:- #1064
I have a stored procedure which deletes a couple of million records and then
I have the following stored procedure, which returns 0 results but if the run
I have the following stored procedure which takes a user ID, a starting date,
I am using Oracle 10g and I have the following stored procedure: CREATE OR
I have the following code within a stored procedure. WHERE WPP.ACCEPTED = 1 AND
I have the following iBatis mapping for an Oracle Stored Procedure that returns a
I have the following statement in a stored procedure: DECLARE @Count INT EXEC @Count
I have a stored procedure which uses a FOR XML statement at the end

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.