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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IN statement using a string

Status
Not open for further replies.

crystalhelp

Programmer
May 13, 2002
56
0
0
CA
I have a string that contains values seperated by commas. I want to use these values in my IN clause.

This is what I mean:

to simplify

branch_string char(10);
branch_string := '1,2,3,4';
select * from branch where branch_id in (branch_string);

How can I do this?

Thanks in advance.

 
Try this:

select * from branch where exists
(select instr(branch_string,branch_id) from branch)
 
You could use dynamic SQL:

branch_string char(10);
branch_string := '1,2,3,4';

EXECUTE IMMEDIATE 'select *
from branch
where branch_id in (' || branch_string || ')';
 

Or,

-- existing
select *
from branch
where INSTR(branch_string, branch_id) > 0;


-- not existing
select *
from branch
where INSTR(branch_string, branch_id) = 0;

Robbie

"The rule is, not to besiege walled cities if it can possibly be avoided" -- Art of War
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top