Solved

Instead of insert question

Posted on 2004-04-09
7
874 Views
Last Modified: 2008-01-09
I am trying to write an instead of insert trigger

-- INSTEAD OF insert on Tertiary Contact views            
      INSERT INTO GWTSDEV.dbcontactperson
             (CONTACTID,
             CONTACTTYPE,            
            TAXID,    
            FIRSTNAME,              
            LASTNAME)          
       VALUES  
             (:contacts.contactid,
                                  :contacts.contacttype,
               :contacts.taxid,
               :contacts.firstname,
               :contcts.lastname);
       commit;
 WHEN duplicate_info THEN
 RAISE_APPLICATION_ERROR (
  num => -21107,
  msg => 'Duplicated Record');
END;

When I use the following code it does not like the 'When' , when I compile. If I use the code below it will compile but when I run the trigger I get FRM-40735:ON-INSERT trigger raised unhandled exception. ORA -00001.

-- INSTEAD OF insert on Tertiary Contact views            
      INSERT INTO GWTSDEV.dbcontactperson
             (CONTACTID,
             CONTACTTYPE,            
            TAXID,    
            FIRSTNAME,              
            LASTNAME)          
       VALUES  
             (:contacts.contactid,
                                  :contacts.contacttype,
               :contacts.taxid,
               :contacts.firstname,
               :contcts.lastname);
       commit;
END;
 

                              
                                    
                        
0
Comment
Question by:uTab
[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
7 Comments
 
LVL 3

Assisted Solution

by:concon
concon earned 125 total points
ID: 10792405
Hi uTab,

try
when DUP_VAL_ON_INDEX then

Regards.
0
 

Author Comment

by:uTab
ID: 10792530
Hi concon,

Now it says that the 'FORM_TRIGGER_FAILURE' is not a proceedure or undefined.

Thanks

 
0
 
LVL 11

Expert Comment

by:pennnn
ID: 10792970
You should use raise_application_error (as you did in your original example), not form_trigger_failure. The form_trigger_failure can be used in Oracle Forms only. It is a predefined exception in Forms, the same way as duplicate_info is a predefined exception in the example from the Oracle SQL Reference manual:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_76a.htm#2064427

You should have copied the DECLARE section also, not only the exception section:
 DECLARE
   duplicate_info EXCEPTION;
   PRAGMA EXCEPTION_INIT (duplicate_info, -00001);

Anyway, it's much cleaner to use concon's suggestion (when_dup_val_on_index).
Hope that helps!
0
Industry Leaders: 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!

 

Author Comment

by:uTab
ID: 10793245
I am using Oracle Forms. The code is as follows:

EXCEPTION
    when DUP_VAL_ON_INDEX then
      Form_Trigger_Failure(
      num => -21107,
      msg => 'Duplicated Contact Information Record');
END;
0
 
LVL 11

Accepted Solution

by:
pennnn earned 125 total points
ID: 10793752
Sorry, the question was misleading - instead of triggers are usually on views, while in forms it's a on-insert trigger...
Anyway, in this case you should use the following:
EXCEPTION
    when DUP_VAL_ON_INDEX then
      raise Form_Trigger_Failure;
END;
Hope that helps!
0
 

Expert Comment

by:bolicat
ID: 11693450
when doing this

SQL> CREATE TRIGGER updDEPT_MAST
  2  INSTEAD OF UPDATE OR INSERT ON vSEL_DEPT_MAST
  3  REFERENCING NEW AS Inserted OLD AS Deleted
  4  BEGIN
  5    IF EXISTS(SELECT 1 FROM Deleted) then
  6       UPDATE DEPT_MAST
  7        SET DEPT_MAST.DEPT_NO = :Inserted.DEPT_NO
  8               ,DEPT_MAST.DEPT_NAME = :Inserted.DEPT_NAME
  9            FROM DEPT_MAST, Inserted
 10            WHERE DEPT_MAST.IMAGE_RECNBR =  :Inserted.IMAGE_RECNBR;
 11      ELSE
 12         INSERT INTO DEPT_MAST SELECT
 13                DEPT_NO
 14               ,DEPT_NAME
 15              FROM Inserted
 16  END
 17  /

getting this

Warning: Trigger created with compilation errors.

SQL>
SQL> show errors trigger updDEPT_MAST;
Errors for TRIGGER UPDDEPT_MAST:

LINE/COL ERROR
-------- -----------------------------------------------------------------
3/6      PL/SQL: SQL Statement ignored
6/11     PL/SQL: ORA-00933: SQL command not properly ended
13/3     PLS-00103: Encountered the symbol "end-of-file" when expecting
         one of the following:
         ;

SQL>
0
 

Author Comment

by:uTab
ID: 11700247
You are missing the ; on lines 15 and 16.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
exp/imp 25 98
SQL Workhours Count beetween Workhours 3 39
Migration from SQL server to oracle (XML input) 4 51
Select the 2 most recent visit dates 5 11
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
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.

740 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