Solved

EXCEPTIONS INTO IN ORACLE

Posted on 2004-09-17
1
1,327 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
Comment Utility
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.

Join & Write a Comment

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now