Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optional Parameters

Status
Not open for further replies.
May 30, 2002
78
US
Hi,

My procedure accepts one parameter, group_id. But its optional. If its left NULL, the program has to process all records. If it has a value, the program process all records with a group_id = the value.

I'm using a cursor that accepts the parameter currently...

CURSOR c_get_gl_rec1(p_group_id) IS
SELECT *
FROM table1
WHERE group_id = p_group_id;

but passing it a NULL won't select all records. Any suggestions?

MG
 
CURSOR c_get_gl_rec1(p_group_id) IS
SELECT *
FROM table1
WHERE group_id like nvl(p_group_id, '%');

may do want you want


I tried to remain child-like, all I acheived was childish.
 
Oops I assumed p_group_id was the parameter, and so wrote it backwards

CURSOR c_get_gl_rec1(p_group_id) IS
SELECT *
FROM table1
WHERE p_group_id like nvl(group_id, '%');

I tried to remain child-like, all I acheived was childish.
 
Cursor with LIKE will not retrieve records with empty group_id.


...WHERE (p_group_id is null or group_id = p_group_id)

Though in stored procedures I prefer to use 2 different cursors because had negative experience on efficiency of such constucts (full scan even with parameter passed) :-(

Regards, Dima
 
Hi,
Why not test the input parameter and use If statements to build your cursor sql code?

[profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top