Hi All,
When I am trying to execute a function I am facing 'oracle character to number conversion error ora-06512'.
My requirement is to update main table based on a selection criteria from the cursor.
In the Cursor , column p_emp_num is stored as multiple employee numbers separated by a comma(child table).
I am trying to remove the comma and fetch it in different rows.
Next I am comparing each of the cursor value to the select query condition. And based on that value the child table is updated.
Please see the details below. Can someone please help .
/**************************/
create table test_cust (Emp_id number ,Emp_num varchar2(50), Emp_type varchar(1) );
insert into test_cust (Emp_id ,Emp_num, Emp_type)
values (3456,'1234,5678,4321', '');
create table test_cust_child (Flag varchar2(1), Emp_num number);
insert into test_cust_child (Flag ,Emp_num)
values ('Y',1234);
insert into test_cust_child (Flag ,Emp_num)
values ('Y',5678);
insert into test_cust_child (Flag ,Emp_num)
values ('Y',4321);
/*********************/
create or replace function Test_cust_func(p_emp_num VARCHAR2)
RETURN VARCHAR2
IS
l_flag VARCHAR2(1);
l_emp_num VARCHAR2(400);
cursor c_emp_num
IS
select regexp_substr(p_emp_num,'[^,]+',1,level) l_emp_num
from dual
connect BY regexp_substr(p_emp_num, '[^,]+', 1, level) is not null;
BEGIN
FOR c_emp_num_rec in c_emp_num
Loop
BEGIN
SELECT flag
INTO l_flag
FROM test_cust_child
WHERE to_char(Emp_num) = c_emp_num_rec.l_emp_num);
dbms_output.put_line('l_flag: '|| l_flag);
UPDATE test\_cust
set Emp\_type = l\_flag
where Emp\_id = 3456;
EXCEPTION
WHEN no\_data\_found
THEN
l\_flag := NULL;
WHEN OTHERS THEN
dbms_output.put_line( SQLERRM );
END;
END LOOP;
commit;
RETURN (l_flag);
END;
/*************************/
declare
result number;
begin
result := Test_cust_func('1234,5678,4321');
end;
Thanks,
RK