Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using a String in the "IN" clause

RoxyrollersJul 2 2013 — edited Jul 2 2013

Hello folks,

    I am trying to output results from a table based on a String which I was planning on using in the "IN" clause. When I run the query through the PL/SQL procedure, I get no results.

In the PL/SQL program, I have a variable p_string where I am appending the ID's in a loop. So, when I print the string, I am seeing '1001','1002','1003' but when I do the following I get nothing.

select * from test_tb

where ID IN (p_string);

Is this because there is an extra quote at the beginning and end of the string and the string is actually ''1001','1002','1003''?

create table test_tb(ID varchar2(4), description varchar2(20));

INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1001', 'Testing 1001');

INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1002', 'Testing 1002');

INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1003', 'Testing 1003');

INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1004', 'Testing 1004');

INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1005', 'Testing 1005');

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 30 2013
Added on Jul 2 2013
2 comments
543 views