Last active
August 29, 2015 14:18
-
-
Save greenkey/89d5e40875ff549022f0 to your computer and use it in GitHub Desktop.
The problem: you have a comma separated string that you have to use for a query.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
a dbms_utility.uncl_array; | |
len PLS_INTEGER; | |
input_string STRING(999) := '0099905666,0099905667,0099905668,0099905669'; | |
my_code STRING(99); | |
BEGIN | |
-- add a letter to make it works | |
input_string := 'x' || Replace(input_string,',',',x'); | |
-- convert the string in an array | |
dbms_utility.Comma_to_table(input_string, len, a); | |
-- loop that array | |
FOR i IN 1..a.count | |
LOOP | |
-- now we have the single value in a variable | |
-- remember to remove the added letter! | |
my_code := Substr(A(i),2,99); | |
-- and then we can use it in a query (just remember the added letter!) | |
FOR cntr IN | |
( SELECT * | |
FROM contracts | |
WHERE contract_code = my_code ) | |
LOOP | |
dbms_output.Put_line( cntr.contract_code ); | |
END LOOP; | |
END LOOP; | |
END;/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by https://community.oracle.com/thread/43542