Solved

EXCEPTIONS INTO IN ORACLE

Posted on 2004-09-17
1
1,341 Views
Last Modified: 2012-06-21
Hi All,
        I have created a table in oracle 9.2.0.5 table name Test columns Id, name.  I have anothe table Audit_test

CREATE TABLE AUDIT_TEST (
   ROW_ID ROWID,
   OWNER VARCHAR2(30),
   TABLE_NAME VARCHAR2(30),
CONSTRAINT VARCHAR2(30));

I have create primay key on the test table like this

ALTER TABLE TEST
ADD CONSTRAINT PK_TEST_ID
PRIMARY KEY(TEST_ID)
EXCEPTIONS INTO AUDIT_TEST;

After that  I have tried to insert into Test table with the same Id  twice like below
INSERT INTO TEST(TEST_ID, TEST_NAME)
VALUES(1,'TEST_1');

It fails to insert into the record but there is no record in Audit_Test. The way I understood the EXCEPTIONS INTO is when ever there is an exception in inserts the record into AUDIT_TEST table but this is not happing.

Can you let me know what does EXCEPTIONS INTO  do and where I am doing wrong.

Thanks,
Cavaturu


0
Comment
Question by:cavaturu
1 Comment
 
LVL 23

Accepted Solution

by:
seazodiac earned 500 total points
ID: 12086504
well, the "EXCEPTIONS INTO" does not work this way....

It only works when you have an EXISTING condition (in which you have a table loaded with duplicate data).

when you try to enable the UNIQUE or PK, then the exceptioned rows go to audit table.

in order for you to make this work.
you have to disable the PK first.

then insert into a bunch of duplicates into the TEST table.
then enable the PK.

then you will see all the exceptioned rows in AUDIT_TEST Table.

assumeing you have issued

ALTER TABLE TEST
ADD CONSTRAINT PK_TEST_ID
PRIMARY KEY(TEST_ID)
EXCEPTIONS INTO AUDIT_TEST;
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I rollback insert statements after commit in oracle? 7 133
Oracle SQL - Query help 7 54
exp/imp 25 73
Can't Access My Database 57 66
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question