Home » SQL & PL/SQL » SQL & PL/SQL » catching exceptions
catching exceptions [message #40869] Fri, 08 November 2002 11:40 Go to next message
thundercat
Messages: 10
Registered: August 2002
Junior Member
Hello all,

I had a post earlier where I was asking if there was a catch all exception handler. Thanks for the responses, I have come up with another problem. The following code produces an error

All I want to do is move data from one table to another, and if something happens like constraint violation, I want to move that data to an error table. The following code is just a tester, and not the actual.

DECLARE v_first_name VARCHAR2(20);
v_last_name VARCHAR2(20);
CURSOR MOVING_DATA IS
SELECT FIRST_NAME, LAST_NAME
FROM ODBC_TABLE1;
BEGIN
OPEN MOVING_DATA;
LOOP
FETCH MOVING_DATA INTO v_first_name, v_last_name;
EXIT WHEN MOVING_DATA%NOTFOUND;
INSERT into ODBC_TABLE2 (FIRST_NAME, LAST_NAME) values (v_first_name, v_last_name);
EXCEPTION
WHEN OTHERS THEN
INSERT INTO ODBC_ERROR_TEST(FIRST_NAME, LAST_NAME)
VALUES(v_first_name, v_last_name);
END;
END LOOP;
CLOSE MOVING_DATA;
END;
Re: catching exceptions [message #40870 is a reply to message #40869] Fri, 08 November 2002 12:24 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
You are missing a BEGIN before the first insert.
Previous Topic: Indexes
Next Topic: Oracle equivalent of an old Centura SQL function
Goto Forum:
  


Current Time: Mon Apr 29 07:38:50 CDT 2024