?
Solved

EXCEPTIONS INTO IN ORACLE

Posted on 2004-09-17
1
Medium Priority
?
1,382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
seazodiac earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

762 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