Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems creating a trigger in Oracle 11g

Tags:

I get a weird error while trying to create a trigger in my Oracle 11g database using SQL Developer. Here is what I did:

My table:

CREATE TABLE COUNTRY_CODE(
   ID NUMBER(19,0)      PRIMARY KEY NOT NULL, 
   Code             VARCHAR2(2) NOT NULL,
   Description  VARCHAR2(50),
   created                  TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 
   created_by                   VARCHAR2(40) DEFAULT USER, 
   last_updated                 TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 
   last_updated_by          VARCHAR2(40) DEFAULT USER,
   archived CHAR(1) DEFAULT '0' NOT NULL );

The Sequence:

CREATE SEQUENCE COUNTRY_CODE_ID_SEQ START WITH 1 INCREMENT BY 1;

The trigger:

CREATE OR REPLACE TRIGGER COUNTRY_CODE_TRIGGER
BEFORE INSERT ON COUNTRY_CODE
FOR EACH ROW
DECLARE
    max_id number;
    cur_seq number;
BEGIN
    IF :new.id IS NULL THEN
    SELECT COUNTRY_CODE_ID_SEQ.nextval
    INTO :new.id
    FROM dual;
ELSE
    SELECT GREATEST(NVL(MAX(id),0), :new.id)
    INTO max_id
    FROM COUNTRY_CODE;

    SELECT COUNTRY_CODE_ID_SEQ.nextval
    INTO cur_seq
    FROM dual;

    WHILE cur_seq < max_id
    LOOP
        SELECT COUNTRY_CODE_ID_SEQ.nextval
        INTO cur_seq
        FROM dual;
    END LOOP;
END IF;
END;

Creating the table and the sequence works very well, but when I try to create my trigger, I get this error:

Error report:
ORA-00603: ORACLE server session terminated by fatal error
ORA-00600: internal error code, arguments: [kqlidchg0], [], [], [], [], [], [], [], [], [], [], []
ORA-00604: error occurred at recursive SQL level 1
ORA-00001: unique constraint (SYS.I_PLSCOPE_SIG_IDENTIFIER$) violated
00603. 00000 -  "ORACLE server session terminated by fatal error"
*Cause:    An ORACLE server session is in an unrecoverable state.
*Action:   Login to ORACLE again so a new server session will be created

Does anyone know about this error?

Thanks

like image 379
David Caissy Avatar asked Jun 06 '13 13:06

David Caissy


People also ask

How do I create a valid trigger in Oracle?

If you omit schema , then Oracle Database assumes the trigger is in your own schema. Specify the name of the trigger to be altered. Specify ENABLE to enable the trigger. You can also use the ENABLE ALL TRIGGERS clause of ALTER TABLE to enable all triggers associated with a table.

Which are 3 basic parts of a trigger?

A trigger has three basic parts: A triggering event or statement. A trigger restriction. A trigger action.

What is the level of creating trigger?

Row-level triggers are the most common type of triggers; they are often used in data auditing applications. Row-level trigger is identified by the FOR EACH ROW clause in the CREATE TRIGGER command. Statement-level triggers execute once for each transaction.


1 Answers

I finally found the answer to my problem:

Add this:

ALTER SESSION SET PLSCOPE_SETTINGS = 'IDENTIFIERS:NONE';

Or in Oracle SQL Developer:

  1. Go to Tools | Preferences
  2. Select Database | PL/SQL Compiler
  3. Change the PLScope identifiers from All to None
  4. Click on Ok

This fixes the issue...

like image 99
David Caissy Avatar answered Nov 06 '22 02:11

David Caissy