Skip to content

Instantly share code, notes, and snippets.

@greenkey
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenkey/89d5e40875ff549022f0 to your computer and use it in GitHub Desktop.
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.
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;/
@greenkey
Copy link
Author

greenkey commented Apr 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment