Procedure not running and not even throwing any error [message #600791] |
Tue, 12 November 2013 10:29 |
|
gupta27
Messages: 31 Registered: August 2013 Location: Delhi
|
Member |
|
|
I have a procedure which is not working properly. It goes into success status without updating any row into main table using the cursor. It happens sometimes only and not always.
below is the code of the procedure:
CREATE OR REPLACE procedure scott.emp_increm_proc as
rows_read number := 0;
rows_inserted number := 0;
rows_updated number := 0;
cursor c1 is select * from emp_increm;
begin
for cur_emp in c1
loop
rows_read := rows_read + 1;
begin
insert into employee ( EMP_NUM, NAME_1, NAME_2,
NAME_3, NAME_4, CITY,
REGION, POSTAL_CD, CNTRY_CD,
CITY_CD, CNTY_CD, CNTY_DESC,
STREET_ADDR, PO_BOX, PO_BOX_POSTAL_CD
)
values ( cur_emp.emp_NUM, cur_emp.NAME_1, cur_emp.NAME_2,
cur_emp.NAME_3, cur_emp.NAME_4, cur_emp.CITY,
cur_emp.REGION, cur_emp.POSTAL_CD, cur_emp.CNTRY_CD,
cur_emp.CITY_CD, cur_emp.CNTY_CD, cur_emp.CNTY_DESC,
cur_emp.STREET_ADDR, cur_emp.PO_BOX, cur_emp.PO_BOX_POSTAL_CD
) ;
rows_inserted := rows_inserted + 1;
exception
when dup_val_on_index
then
rows_updated := rows_updated + 1;
update employee c
set c.NAME_1 = cur_emp.NAME_1,
c.NAME_2 = cur_emp.NAME_2,
c.NAME_3 = cur_emp.NAME_3,
c.NAME_4 = cur_emp.NAME_4,
c.CITY = cur_emp.CITY,
c.REGION = cur_emp.REGION,
c.POSTAL_CD = cur_emp.POSTAL_CD,
c.CNTRY_CD = cur_emp.CNTRY_CD,
c.CITY_CD = cur_emp.CITY_CD,
c.CNTY_CD = cur_emp.CNTY_CD,
c.CNTY_DESC = cur_emp.CNTY_DESC,
c.STREET_ADDR = cur_emp.STREET_ADDR,
c.PO_BOX = cur_emp.PO_BOX,
c.PO_BOX_POSTAL_CD = cur_emp.PO_BOX_POSTAL_CD
where c.emp_num = cur_emp.emp_num;
end;
commit;
end loop;
dbms_output.put_line('Read ' || rows_read);
dbms_output.put_line('Inserted ' || rows_inserted);
dbms_output.put_line('Updated ' || rows_updated);
end emp_increm_proc;
Is it because I have not explicitly mentioned the schema name for the tables used in the procedure.
Note: There are no other tables in the database (and schema)with these names.
How can I handle these scenarios in exception, so that it would throw failure status when read = 0(i.e when procedure is not able to read anything from the cursor table)
|
|
|
|
|
|
|
|
|