Solved

EXCEPTIONS INTO IN ORACLE

Posted on 2004-09-17
1
1,361 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
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.

734 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