Wednesday, March 24, 2010

dbms_utility.comma_to_table

This is the name of the proc which made my life much easier today. I had a requirement to update a table based on two parameters passed to a procedure. The update would have been simple had those parameters been tow columns corresponding to the two columns in a table. But those two parameters would be a comma separated strings. I need to derive the values by parsing the strings.
Below is a sample program used to solve this issue.


create or replace procedure emp_upd_prc
(ip_ename varchar2,
ip_ename_upd varchar2) as

l_ename_upd_array dbms_utility.uncl_array;
l_count binary_integer;
l_ename_array dbms_utility.uncl_array;

begin

dbms_utility.comma_to_table(ip_ename,l_count,l_ename_array);
dbms_utility.comma_to_table(ip_ename_upd,l_count,l_ename_upd_array);


for i in 1..l_count
loop

update emp
set ename = l_ename_upd_array(i)
where ename = l_ename_array(i);

end loop;

end emp_upd_prc;
/

But the limitations with using dbms_utility.comma_to_tabs procedure is that it can not take number string. Like in my case i tried to send a list of empno as the first parameter and a list of names as the second parameter. But i am getting the following error.

ERROR at line 1:
ORA-20001: comma-separated list invalid near 4
ORA-06512: at "SYS.DBMS_UTILITY", line 238
ORA-06512: at "SYS.DBMS_UTILITY", line 255
ORA-06512: at "SCOTT.EMP_UPD_PRC", line 12
ORA-06512: at line 1

After some googling I found that this procedure have some limitations. It does not accept numbers or special characters in strings. I guess there should be some way to overcome these issues. But as of now my requirement luckily has character data as both the parameters and not numeric, in which case I would have spent more time of finding the alternatives to the problem.

No comments: