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 ?
Try this:
Here is a sqlfiddle demo
UPDATE
If you want to use the same cursor for different functions then you can do it like this: