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 9229351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:32:59+00:00 2026-06-18T05:32:59+00:00

I want to use single cursor to fetch single record or all records using

  • 0

I want to use single cursor to fetch single record or all records using where condition, e.g. : student is table and sid is an attribute.

I have two cursors,

DECLARE S1 CURSOR FOR SELECT * FROM Student;

and

Declare S2 Cursor for select * from Student where sid=11

My query is on how to combine these two conditions to use only one cursor. I need this as I have two functions m_viewStudent and m_viewallStudents, for this I would like to use only one cursor to display the requested details from table.

so how can I achieve this ?

  • 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-18T05:33:01+00:00Added an answer on June 18, 2026 at 5:33 am

    Try this:

    select * 
    from student
    where sid = 11 
    or not exists (select 1 from student where sid = 11)
    

    Here is a sqlfiddle demo


    UPDATE

    If you want to use the same cursor for different functions then you can do it like this:

    create package p is
    
      procedure one_sid(in_sid number);
      procedure all_sid;
    
    end p;
    /
    
    create package body p is
    
      cursor c(p_sid number) is
      select * 
        from student 
       where sid = p_sid or p_sid is null;
    
      procedure one_sid(in_sid number) is
    
      begin
    
       open c(in_sid);
    
       close c;
    
      end;
    
      procedure all_sid is
    
      begin
    
       open c(null);
    
       close c;
    
      end;
    
    end p;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use a single php file to handle all of my voting requests.
First of all: I want to use Java EE not Spring! I have some
I want to use a single query to insert into a table and if
I am adding batches of records to a table using a single insert statement.
I have an app using fragments, all of which are contained in a single
I have several subclasses of UIViewController that I want to use a single category
I want to use a single Doctrine install on our server and serve multiple
I want to use a single font named Algerian across my whole website. So,
I am building a simple particle system and want to use a single array
I want to use BackboneJS for single page sites. The structure I am thinking

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.