Trigger Bad Bind Value Auto Increment

I am new to the Oracle world and am trying to make the switch from MySQL so my apologies if this seems like a silly question.
I am trying to figure out what is wrong with my trigger code. Basically , I am trying to create an auto-increment solution using some example code I found on the Internet.
I have a fairly simple table structure:
CREATE TABLE "CIMS"."computerSoftware"
( "computerSoftware_id" NUMBER(11,0),
"cid" NUMBER(11,0) DEFAULT 0 NOT NULL ENABLE,
"publisher" VARCHAR2(100 CHAR) DEFAULT NULL,
"name" VARCHAR2(100 CHAR) DEFAULT NULL,
"version" VARCHAR2(100 CHAR) DEFAULT NULL,
"serialNumber" VARCHAR2(100 CHAR) DEFAULT NULL,
"unlimited" NUMBER(4,0) DEFAULT 0,
"copies" NUMBER(9,0) DEFAULT 1 NOT NULL ENABLE,
"master" NUMBER(4,0) DEFAULT 0,
PRIMARY KEY ("computerSoftware_id")
My Trigger looks like this:
CREATE OR REPLACE TRIGGER "CIMS"."TR_CompSoftware_ID"
BEFORE INSERT ON CIMS."computerSoftware"
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
IF (:new.computerSoftware_id IS NULL) then
SELECT S_CompSoftware_ID.NEXTVAL
INTO :new.computerSoftware_id
FROM dual;
end IF;
END;
And finally, here is my sequence:
CREATE SEQUENCE "CIMS"."S_CompSoftware_ID" MINVALUE 1
MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 10 NOORDER NOCYCLE
When I try to save the trigger I receive the following error:
PLS-00049: bad bind variable 'NEW.COMPUTERSOFTWARE_ID'
Any help is much appreciated!
Tom

And, this is the way - you can rectify this problem ->
satyaki>
satyaki>drop table "computerSoftware";
Table dropped.
Elapsed: 00:00:00.92
satyaki>
satyaki>CREATE TABLE computerSoftware
  2  (  
  3      computerSoftware_id NUMBER(11,0),
  4      cid NUMBER(11,0) DEFAULT 0 NOT NULL ENABLE,
  5      publisher VARCHAR2(100 CHAR) DEFAULT NULL,
  6      name VARCHAR2(100 CHAR) DEFAULT NULL,
  7      version VARCHAR2(100 CHAR) DEFAULT NULL,
  8      serialNumber VARCHAR2(100 CHAR) DEFAULT NULL,
  9      un_limited NUMBER(4,0) DEFAULT 0,  -- Need to change the name of your column due to use of reserve word
10      copies NUMBER(9,0) DEFAULT 1 NOT NULL ENABLE,
11      master NUMBER(4,0) DEFAULT 0,
12     constraints pk_cid PRIMARY KEY (computerSoftware_id)
13   );
Table created.
Elapsed: 00:00:00.20
satyaki>
satyaki>
satyaki>CREATE SEQUENCE S_CompSoftware_ID MINVALUE 1
  2  MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 10 NOORDER NOCYCLE;
Sequence created.
Elapsed: 00:00:00.05
satyaki>
satyaki>
satyaki>CREATE OR REPLACE TRIGGER TR_CompSoftware_ID
  2  BEFORE INSERT ON computerSoftware
  3  REFERENCING OLD AS OLD NEW AS NEW
  4  FOR EACH ROW
  5  BEGIN
  6    IF (:new.computerSoftware_id IS NULL) then
  7        SELECT S_CompSoftware_ID.NEXTVAL
  8        INTO :new.computerSoftware_id
  9        FROM dual;
10    end IF;
11  END;
12  /
Trigger created.
Elapsed: 00:00:00.98
satyaki>
satyaki>insert into computerSoftware(cid,publisher,name,version,serialNumber,un_limited,copies,master)
  2     values(1,'ABP','SR','1.0.0.1','1.4.3',88,7,9);
1 row created.
Elapsed: 00:00:00.14
satyaki>
satyaki>commit;
Commit complete.
Elapsed: 00:00:00.05
satyaki>
satyaki>
satyaki>select * from computerSoftware;
COMPUTERSOFTWARE_ID        CID PUBLISHER                                                                                            NAME                                                                                                 VERSION                                                                       
                  1          1 ABP                                                                                                  SR                                                                                                   1.0.0.1                                                                       
Elapsed: 00:00:00.05
satyaki>Got me?
Regards.
Satyaki De.

Similar Messages

  • How to insert into table when ID auto increment?

    I have a table Employee with EmloyeeID, EmployeeName, Email...
    When i design table in database, i created a Sequence and then Trigger for EmployeeID to auto increment.
    Now in ADF, actually in my web form: I don't want enter values for EmployeeID to insert into table,
    but still error : required for EmployeeID...
    how can i do it? Thanks

    User,
    Always mention your JDev version every time you start a new thread.
    Check this out : Andrejus Baranovskis Blog: How To Implement Gapless Sequence in ADF BC
    -Arun

  • Bad bind variable error on creating trigger

    hi
    im trying to create a trigger on a table in Oracle and I keep gettin this error:
    PLS-00049: bad bind variable 'NEW.ID'
    TeamID is a primary Key, it creates the sequence fine, but i get the error on the create trigger,
    CREATE TABLE TBLTEAMS
    TEAMID NUMBER(5),
    NAME VARCHAR2(50 BYTE),
    MANAGER VARCHAR2(50 BYTE),
    COSTCENTRE NUMBER(9),
    PARENTTEAMID NUMBER(5)
    create sequence seq_Teamsautonumber;
    create trigger trg_Teamsautonumber
    before insert on tblteams
    for each row
    begin
    select seq_Teamsautonumber.nextval into :new.id from dual;
    end;
    any ideas?

    You have said
    :new.idthat means you are trying to load the sequence value into a column that doesn't exist in your table.
    you would need to use
    :new.teamidAssuming you are trying to auto-populate the TEAMID column on your table.

  • Error in trigger: PLS-00049: bad bind variable

    Hi,
    I am trying one of the XML/XDK samples from technet (http://otn.oracle.com/tech/xml/htdocs/XDBDemo2.html) and get this error while compiling the trigger: here's the code snippet
    create or replace trigger PURCHASEORDEREXPLOSION
    instead of insert on NEWPURCHASEORDER
    for each row
    declare
    begin
    DOCUMENT := :new.PODOCUMENT; <--Error here: PLS-00049: bad bind variable 'NEW.PODOCUMENT'
    I can't understand why is this happening? Any clues??
    Thanks!
    -Rajeev

    You don't specify bind variables with the colon ":" prefix in PL/SQL.
    The procedure you posted builds a query using string concatenation. Even if you remove the colon from your variable name you still won't be using bind variables.
    If you want to use bind variables you should consider doing the following:
    1. Use the DBMS_SQL package.
    2. Use EXECUTE IMMEDIATE with the USING clause.
    3. Use OPEN <REF CURSOR> FOR <STATEMENT> with the USING clause.
    Each one has different advantages/disadvantages.
    If looks as if you want to pass in a dynamic IN list. If you use bind variables it will effectively treat the entire list as ONE value enclosed in single quotes. If you truly want a dynamic IN list you need to investigate another method.
    Tom Kyte has some information on Dynamic IN lists here: [How can I do a variable in list?|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425]

  • TRIGGER ERROR: bad bind variable

    Hello,
    I'm just starting off with oracle and am trying to do the same as auto_increment in mysql is doing by creating this sequence and trigger, but on the trigger I am getting the following error:
    error:
    PLS-00049: bad bind variable 'TAKEOVER_USERS.TAKEOVER_UID'This is the code for trigger, table and sequence:
    trigger:
    CREATE OR REPLACE TRIGGER  "TAKEOVER_USERS_T1"
    BEFORE
    insert on "TAKEOVER_USERS"
    for each row
    begin
    select TAKEOVER_UID.nextval into :takeover_users.TAKEOVER_UID from dual;
    end;Table:
    CREATE TABLE  "TAKEOVER_USERS"
       ( "TAKEOVER_UID" NUMBER NOT NULL ENABLE,
    "TAKEOVER_FBID" VARCHAR2(20) NOT NULL ENABLE,
    "takeover_accepted_terms" NUMBER(1,1) NOT NULL ENABLE,
    "takeover_lastName" VARCHAR2(30),
    "takeover_firstName" VARCHAR2(30),
    "takeover_country" VARCHAR2(40),
    "takeover_session" VARCHAR2(50) NOT NULL ENABLE,
    "takeover_created" TIMESTAMP (6) NOT NULL ENABLE,
      CONSTRAINT "takeover_users_PK" PRIMARY KEY ("TAKEOVER_UID") ENABLE
       )sequence:
    CREATE SEQUENCE   "TAKEOVER_UID"  MINVALUE 1 MAXVALUE 99999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLEYou got any idea what I need to change to make this work?
    Thanks!
    Christine

    if your DB is 11g you can try this
    CREATE OR REPLACE TRIGGER  "TAKEOVER_USERS_T1"
    BEFORE
    insert on "TAKEOVER_USERS"
    for each row
    begin
    :NEW.TAKEOVER_UID:=TAKEOVER_UID.nextval;
    end;if 10g or older..
    CREATE OR REPLACE TRIGGER  "TAKEOVER_USERS_T1"
    BEFORE
    insert on "TAKEOVER_USERS"
    for each ROW
    BEGIN
    SELECT TAKEOVER_UID.NEXTVAL INTO :NEW.TAKEOVER_UID FROM dual;
    end;Regards,
    Prazy

  • BAD BIND Variable in Trigger

    What's wrong with this script
    desc     psaudit;
    Name               Type
    AUDIT_OPRID     VARCHAR2(30)
    AUDIT_STAMP     DATE
    AUDIT_ACTN     VARCHAR2(1)
    RECNAME          VARCHAR2(15)
    FIELDNAME          VARCHAR2(18)
    OLDVALUE          VARCHAR2(65)
    NEWVALUE          VARCHAR2(65)
    KEY1               VARCHAR2(65)
    KEY2               VARCHAR2(65)
    KEY3               VARCHAR2(65)
    KEY4               VARCHAR2(65)
    KEY5               VARCHAR2(65)
    KEY6               VARCHAR2(65)
    KEY7               VARCHAR2(65)
    KEY8               VARCHAR2(65)
    KEY9               VARCHAR2(65)
    KEY10          VARCHAR2(65)
    KEY11          VARCHAR2(65)
    KEY12          VARCHAR2(65)
    KEY13          VARCHAR2(65)
    KEY14          VARCHAR2(65)
    KEY15          VARCHAR2(65)
    22     rows     selected
    CREATE OR REPLACE TRIGGER JOB_TR
    AFTER INSERT OR UPDATE OR DELETE ON PS_JOB_BT
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    V_AUDIT_OPRID VARCHAR2(64);
    BEGIN
    DBMS_APPLICATION_INFO.READ_CLIENT_INFO(V_AUDIT_OPRID);
    IF :OLD.RECNAME IS NULL
    THEN
    INSERT INTO PSAUDITWRK
    VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'I',:NEWRECNAME,:NEWFIELDNAME,:NEWOLDVALUE,:NEWNEWVALUE,:NEWKEY1,:NEWKEY2,:NEWKEY3,:NEWKEY4,:NEWKEY5,:NEWKEY6,:NEWKEY7,:NEWKEY8,:NEWKEY9,:NEWKEY10,:NEWKEY11,:NEWKEY12,:NEWKEY13,:NEWKEY14,:NEWKEY15);
    ELSE
    IF :NEWRECNAME IS NULL
    THEN
    INSERT INTO PSAUDITWRK
    VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'D',:OLD.RECNAME,:OLD.FIELDNAME,:OLD.OLDVALUE,:OLD.NEWVALUE,:OLD.KEY1,:OLD.KEY2,:OLD.KEY3,:OLD.KEY4,:OLD.KEY5,:OLD.KEY6,:OLD.KEY7,:OLD.KEY8,:OLD.KEY9,:OLD.KEY10,:OLD.KEY11,:OLD.KEY12,:OLD.KEY13,:OLD.KEY14,:OLD.KEY15);
    ELSE
    INSERT INTO PSAUDITWRK
    VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'B',:OLD.RECNAME,:OLD.FIELDNAME,:OLD.OLDVALUE,:OLD.NEWVALUE,:OLD.KEY1,:OLD.KEY2,:OLD.KEY3,:OLD.KEY4,:OLD.KEY5,:OLD.KEY6,:OLD.KEY7,:OLD.KEY8,:OLD.KEY9,:OLD.KEY10,:OLD.KEY11,:OLD.KEY12,:OLD.KEY13,:OLD.KEY14,:OLD.KEY15);
    INSERT INTO PSAUDIT
    VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'A',:NEWRECNAME,:NEWFIELDNAME,:NEWOLDVALUE,:NEWNEWVALUE,:NEWKEY1,:NEWKEY2,:NEWKEY3,:NEWKEY4,:NEWKEY5,:NEWKEY6,:NEWKEY7,:NEWKEY8,:NEWKEY9,:NEWKEY10,:NEWKEY11,:NEWKEY12,:NEWKEY13,:NEWKEY14,:NEWKEY15);
    END IF;
    END IF;
    END JOB_TR;
    Warning: compiled but with compilation errors
    LINE/COL ERROR
    5/4 PLS-00049: bad bind variable 'OLD.SYSADM'
    8/49 PLS-00049: bad bind variable 'NEW.RECNAME'
    8/62 PLS-00049: bad bind variable 'NEW.FIELDNAME'
    8/77 PLS-00049: bad bind variable 'NEW.OLDVALUE'
    8/91 PLS-00049: bad bind variable 'NEW.NEWVALUE'
    8/105 PLS-00049: bad bind variable 'NEW.KEY1'
    8/115 PLS-00049: bad bind variable 'NEW.KEY2'
    8/125 PLS-00049: bad bind variable 'NEW.KEY3'
    8/135 PLS-00049: bad bind variable 'NEW.KEY4'
    8/145 PLS-00049: bad bind variable 'NEW.KEY5'
    8/155 PLS-00049: bad bind variable 'NEW.KEY6'
    LINE/COL ERROR
    8/165 PLS-00049: bad bind variable 'NEW.KEY7'
    8/175 PLS-00049: bad bind variable 'NEW.KEY8'
    8/185 PLS-00049: bad bind variable 'NEW.KEY9'
    8/195 PLS-00049: bad bind variable 'NEW.KEY10'
    8/206 PLS-00049: bad bind variable 'NEW.KEY11'
    8/217 PLS-00049: bad bind variable 'NEW.KEY12'
    8/228 PLS-00049: bad bind variable 'NEW.KEY13'
    8/239 PLS-00049: bad bind variable 'NEW.KEY14'
    8/250 PLS-00049: bad bind variable 'NEW.KEY15'

    Hi,
    Your trigger still don't have any reference to OLD.SYSADM, meaning those compile errors are from something else.
    You should
    1. Format your trigger (Which you have to some degree)
    2. Paste it into SQL*Plus
    3. Followed it by alter trigger ... compile
    4. And show errors.
    5. Paste back everything here
    6. Remember to enclose SQL*Plus output in {noformat}{noformat} tags
    Regards
    Peter
    edit:
    I take back what I said about formatting. This is how it looks formatted:create or replace trigger job_tr
    after insert or update or delete
    on ps_job_bt
    referencing new as new old as old
    for each row
    declare
    v_audit_oprid varchar2(64);
    begin
    dbms_application_info.read_client_info(v_audit_oprid);
    if :old.recname is null
    then
    insert into psauditwrk
    values (get_ps_oprid(v_audit_oprid)
    ,sysdate
    ,'I'
    ,:newrecname
    ,:newfieldname
    ,:newoldvalue
    ,:newnewvalue
    ,:newkey1
    ,:newkey2
    ,:newkey3
    ,:newkey4
    ,:newkey5
    ,:newkey6
    ,:newkey7
    ,:newkey8
    ,:newkey9
    ,:newkey10
    ,:newkey11
    ,:newkey12
    ,:newkey13
    ,:newkey14
    ,:newkey15);
    else
    if :newrecname is null
    then
    insert into psauditwrk
    values (get_ps_oprid(v_audit_oprid)
    ,sysdate
    ,'D'
    ,:old.recname
    ,:old.fieldname
    ,:old.oldvalue
    ,:old.newvalue
    ,:old.key1
    ,:old.key2
    ,:old.key3
    ,:old.key4
    ,:old.key5
    ,:old.key6
    ,:old.key7
    ,:old.key8
    ,:old.key9
    ,:old.key10
    ,:old.key11
    ,:old.key12
    ,:old.key13
    ,:old.key14
    ,:old.key15);
    else
    insert into psauditwrk
    values (get_ps_oprid(v_audit_oprid)
    ,sysdate
    ,'B'
    ,:old.recname
    ,:old.fieldname
    ,:old.oldvalue
    ,:old.newvalue
    ,:old.key1
    ,:old.key2
    ,:old.key3
    ,:old.key4
    ,:old.key5
    ,:old.key6
    ,:old.key7
    ,:old.key8
    ,:old.key9
    ,:old.key10
    ,:old.key11
    ,:old.key12
    ,:old.key13
    ,:old.key14
    ,:old.key15);
    insert into psaudit
    values (get_ps_oprid(v_audit_oprid)
    ,sysdate
    ,'A'
    ,:newrecname
    ,:newfieldname
    ,:newoldvalue
    ,:newnewvalue
    ,:newkey1
    ,:newkey2
    ,:newkey3
    ,:newkey4
    ,:newkey5
    ,:newkey6
    ,:newkey7
    ,:newkey8
    ,:newkey9
    ,:newkey10
    ,:newkey11
    ,:newkey12
    ,:newkey13
    ,:newkey14
    ,:newkey15);
    end if;
    end if;
    end job_tr;
    It is immediately seen that this
          if :newrecname is null
    Should be
          if :new.recname is null
    And this error isn't even shown in your eledged compile errors.
    Edited by: Peter Gjelstrup on Feb 10, 2009 7:00 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • AUTO Increment on TABLE or TRIGGER

    I have a table that I created. I want the first column in the table to auto increment. Some of the examples I have seen create a sequence, and then do the update on a trigger?
    Is is possible to just start with 1 and increment by one when something is inserted into the table in the CREATE or ALTER Table syntax?
    Or Do I have to create a sequence, and trigger for this?

    I have already created a trigger for this table. I am doing an insert.
    IF UPDATE THEN
      INSERT INTO EQUIPMENT_USER_DATA_AUDIT (
        equipment_id,
        old_cpe_status,
        new_cpe_status,
        cpe_status_changed,
        old_ne_status,
        new_ne_status,
        ne_status_changed,
        date_modified,
        modifiers_name)
    VALUES (
        :new.equipment_id,
        :old.cpe_status,
        :new.cpe_status,
        (CASE WHEN :old.cpe_status = :new.cpe_status
               THEN 'N'
               ELSE 'Y'
         END),
        :old.ne_status,
        :new.ne_status,
        (CASE WHEN :old.ne_status = :new.ne_status
               THEN 'N'
               ELSE 'Y'
         END),
        SYSDATE,
        SYS_CONTEXT ('USERENV','CURRENT_SCHEMA'));
       END IF;Do I need to declare the first column in my insert? which is named seq_id?

  • PLS-00049: bad bind variable 'NEW.ID' on trigger

    Hi guys, I am using Oracle SQL Developer version 2.1.1.64 and having the sql statement like below
    CREATE TABLE Zipcodes
         zipcode_id NUMBER(10),
         zipcode VARCHAR2(10),
         district_id NUMBER(10),
         PRIMARY KEY(zipcode_id)
    CREATE SEQUENCE ZIPCODE_ID_SEQ START WITH 1 INCREMENT BY 1;
    CREATE OR REPLACE TRIGGER ZIPCODE_TRIGGER
    BEFORE INSERT
    ON ZIPCODES
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
         SELECT ZIPCODE_ID_SEQ.NEXTVAL INTO :NEW.ZIPCODE_ID FROM DUAL;
    END;
    And I got errors:
    Error(2,40): PLS-00049: bad bind variable 'NEW.ID'
    Error(4,5): PL/SQL: Statement ignored
    Error(4,39): PLS-00357: Table,View Or Sequence reference 'ZIPCODE_ID_SEQ.NEXTVAL' not allowed in this context
    Error(2,36): PLS-00049: bad bind variable 'NEW.ID'
    Error(2,2): PL/SQL: SQL Statement ignored
    Error(2,9): PL/SQL: ORA-02289: sequence does not exist
    Error(5,1): PLS-00103: Encountered the symbol "SHOW"
    Firstly, I dont even have the "SHOW" key world in my syntax.
    What is it happening ?
    Thank you in advance.

    Hi,
    954390 wrote:
    Hi guys, I am using Oracle SQL Developer version 2.1.1.64 Thanks; that could be useful information. Even more important is your database version (e.g. 11.2.0.2.0)
    and having the sql statement like below
    CREATE TABLE Zipcodes
         zipcode_id NUMBER(10),
         zipcode VARCHAR2(10),
         district_id NUMBER(10),
         PRIMARY KEY(zipcode_id)
    )Don't you need a semicolin or a slash after the CREATE TABLE statement?
    CREATE SEQUENCE ZIPCODE_ID_SEQ START WITH 1 INCREMENT BY 1;Did you get a message like "Sequence created" at this point?
    CREATE OR REPLACE TRIGGER ZIPCODE_TRIGGER
    BEFORE INSERT
    ON ZIPCODES
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
         SELECT ZIPCODE_ID_SEQ.NEXTVAL INTO :NEW.ZIPCODE_ID FROM DUAL;
    END;
    And I got errors:
    Error(2,40): PLS-00049: bad bind variable 'NEW.ID'
    Error(4,5): PL/SQL: Statement ignored
    Error(4,39): PLS-00357: Table,View Or Sequence reference 'ZIPCODE_ID_SEQ.NEXTVAL' not allowed in this context
    Error(2,36): PLS-00049: bad bind variable 'NEW.ID'
    Error(2,2): PL/SQL: SQL Statement ignored
    Error(2,9): PL/SQL: ORA-02289: sequence does not exist
    Error(5,1): PLS-00103: Encountered the symbol "SHOW"
    Firstly, I dont even have the "SHOW" key world in my syntax.
    What is it happening ?You don't have anything like NEW.ID, either.
    Also, the line numbers in error messages for triggers start with the first DECLARE or BEGIN statement, so this trigger only has 3 lines, yet you're getting line numbers up to 5 in the error messages.
    That trigger works fine for me in SQL*Plus (database 10.2.0.1.0).
    Are you sure you're showing the complete script, exactly what you're running? If you had some syntax error before the CREATE OR REPLACE TRIGGER statement, that might possibly account for the parser getting confused.
    Does your code work in SQL*Plus?

  • Add auto increment column to trigger

    I want to add auto increment column to after insert trigger. so how can I do that?

    this is my query.
    Create Sequence Up_Seq
    Start With 1
    Increment By 1
    nomaxvalue;
    Create Or Replace Trigger Upf_Trig
    After Insert On members
    Referencing New As New
    For Each Row
    Begin
    Insert Into Upf_Kgl(Member_Id,Mem_Name,Nic,Division)
    Values (Up_Seq.Nextval
    *,:New.Mem_Name*
    *,:New.Nic*
    *,:New.Division);*
    end upf_trig;
    It's worked. but when inserting values to members table, there is an error.
    this is the error
    Error starting at line 21 in command:
    Insert Into Members(Mem_Name,Nic,Full_Name,Age,Sex,Mar_State,Birth_Date,Division,Religon)
    Values(
    *'IA Nawagamuwa'*
    *,'883324356V'*
    *,'Isuru Aravinda Nawagamuwa'*
    *,'22'*
    *,'Male'*
    *,'Single'*
    *,'21-Dec-88'*
    *,'kgl'*
    *,'Buddhist')*
    Error report:
    SQL Error: ORA-00001: unique constraint (SYSTEM.SYS_C004077) violated
    ORA-06512: at "SYSTEM.UPF_TRIG", line 2
    ORA-04088: error during execution of trigger 'SYSTEM.UPF_TRIG'
    *00001. 00000 - "unique constraint (%s.%s) violated"*
    **Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.*
    For Trusted Oracle configured in DBMS MAC mode, you may see
    this message if a duplicate entry exists at a different level.
    **Action: Either remove the unique restriction or do not insert the key.*

  • How to create auto increment value in my column using identity ?

    hi Team,
    I have an requirement where i create an auto increment value ,with my table column
    Create table Temp(
    DeptID int IDENTITY(1,1) PRIMARY KEY,
    Name varchar(50),
    Emailid nvarchar(50),
    Phone varchar(50)
    so this is my table structure ,Here my column name is
    Deptid here i need to creat an autoincrement value with today's date like below
    ex:STM0000120012015
        STM0000221012015
        STM0000322012015(Currentdate)
    .......................................... like this
    Here i need  only one column like identity column with the given incremental order,not more than one column
    so can u pls help me out any one.
    Thanks!

    Here the output came like this ,
    1 STM0000120150121
    2 STM0000220150121
    3 STM0000320150121
    4 STM0000420150121
    5 STM0000520150121
    6 STM0000620150121
    7 STM0000720150121
    8 STM0000820150121
    9 STM0000920150121
    10 STM00001020150121 --see this exceed length
    and here i dnt need to increment that Stm000010,Here my output will come like this, idnt need to increment my charcter size
    1 STM0000120150121
    2 STM0000220150121
    3 STM0000320150121
    4 STM0000420150121
    5 STM0000520150121
    6 STM0000620150121
    7 STM0000720150121
    8 STM0000820150121
    9 STM0000920150121
    10 STM0001020150121
    11    STM0001120150121
    12    STM0001220150121 
    so here i dont  need to increment my charcter length(16)
    The length should be STM(3char)+00001(5Charcters)+CurrentDateFormat,
    see the above suggested o/p
    so can u pls help me out Dimant

  • Not authorised to have auto increment trigger on server

    Hello all. I need a few triggers set up, I have no problems setting up sequences and "before insert" triggers on my home PC setup but on the live server where I study I do not have the authority.
    I got around this before by using Forms so I set the trigger at Form level.
    I am developing a DB system that will at some stage in the future use Forms, but for now it will use HTML forms via a web browser.
    I need to have the primary key for user accessible tables to be auto incremented (on the server where I study), but how can get around the authority issue ??
    Any ideas are extremely welcome !!

    Hello all - yeah I am on a course. I too have no idea why they will not allow the students to create triggers at table level.
    The 1st system I developed at home I had auto incremented primary keys. It was using Oracle Forms as the front end. Because I am the admin on my home setup I didn't have any problems.
    When I went to the course site to implement exactly what I had at home (which worked 100% properly) inserting data via the forms was not working. I had no idea why. the lecturer guy took a look at my code and told me its because of the trigger, I do not have authority to create triggers on the server.
    "create or replace trigger cust_trg
    before insert on customer
    for each row
    begin
    select cust_seq.nextval into :new.cust_id
    from dual;
    end;"
    The above code works fine on my home PC. I used Pre Insert triggers on the block on the Form instead to get around the problem (I presumed it was because they wanted us to learn Forms more thoroughly).
    This next project does not involve forms but they will not change my access rights so I don't have a clue as to how to get an auto incremented primary key whilst using a HTML form.
    Kevin

  • How to get the auto increment integer primary key value of a new record

    I have a DB table that has a auto increment integer primary key, if I insert a new record into it by SQL statement "INSERT INTO...", how can I get the integer primary key value of that newly created record?

    Well maybe someone knows a better method, but one workaround would be to add a dummy field to your table. When a new record is inserted this dummy field will be null. Then you can select your record with SELECT keyField FROM yourTable WHERE dummyField IS NULL. Once you've got the key number, you then update the record with a non-null value in the dummyField. Bit of a bodge, but it should work...
    Another alternative is, instead of using an Autonumbered key field, you could assign your own number by getting the MAX value of the existing keys (with SELECT MAX(keyField) FROM yourTable) and using that number + 1 for your new key. Might be a problem if you have lots of records and frequent deletions though.

  • How to get auto-increment value after insert on ACCESS db?

    When you insert a new record to a table with an auto-incrementing key, how do you find the value for the row you just inserted? This works differently with different databases. I know how it's done on ORACLE and mySql.
    How does it work with ACCESS through ODBC? How about MSSQL?

    I have discovered there's a LAST aggregate function which when I've tested it gets the just inserted auto-increment, but I'm not sure if it's reliable. You have to do:
    SELECT LAST(index-field) FROM table
    That ought to be faster than MAX, which I've noticed some people use. Persumable LAST will get the value from the last row in the table's natural order.
    In fact an auto-increment field has no business filling in missing slots since the main point is a a foreign key in other tables and a foreign key pointing to a deleted table row ought to be invalidated, not point to some unrelated successor record.
    I could use a separate table as a source of counters, of course, though that's one more call. In either case I'm worried about thread safety. In Oracle there are special sequence objects for this purpose which are incremented and read atomically. I'm not sure if the access driver transaction handling works adequately.
    Perhaps the safest approach might be to use a separate sequencer table and Java sychronisation to serialise access to each row in the sequencer table (assuming all the access is from the same app).

  • Auto Increment of primary key value in jdeveloper.

    hi all,
    i have one table with one primary key.
    i want to increment that primary key when ever i go for CreateInsert or create operation in JSF page.
    i have tried with db sequence value type, but i was not able to achieve my condition. in DB Sequence i got error like cannot convert java.class.string to java.class.dbsequence.
    can any one suggest me in this to achieve my condition.
    regards,
    M vijayalakshmi.

    hi all,
    from this i found the simple method to achive the auto increment of primary key.
    http://www.techartifact.com/blogs/2012/10/adding-number-for-primary-key-in-oracle-adf-using-groovy-by-sequence.html#ixzz2EeU9CWo6
    in this am facing an one small issue.
    intial value of the primary key is 1.
    for this value i have entered the row of data.
    again i have clicked on the create button.
    then the value of the primary key has increased to 2.
    for this value i didnt entered the row of data to databse.
    just i closed the browser.
    if i run the run page again, the value of primary key is 3.
    my requirment is i shd get the value of primary key is "2".
    the increment shd happen the maxi value present in the primary key of the table.
    can any one help me in this how to achive this.
    thanks in advance.
    regards,
    M vijayalakshmi.

  • Update table column with same auto-increment value, via T-SQL stored procedure

    Good Evening to every one,
    I have a table 'Contracts' as we can see in the picture below (I exported my data on An Excel Spreadsheet). Table's primary key is 'ID' column.
    I am trying to create a stored procedure (i.e. updContractNum), through which I am going to update the 'Contract_Num' column, in every row where the values on Property_Code, Customer, Cust_Category and Amnt ARE EQUAL, as we can see in the schema above.
    The value of Contract_Num is a combination of varchar and auto_increment (integer). For example, the next value on 'Contract number' column will be 'CN0005' for the combination of 11032-14503-02-1450,00
    I' m trying to use CURSORS for this update but I am new in using cursors and I am stuck in whole process. I atttach my code below:
    CREATE PROCEDURE updContractNum
    AS
    --declare the variables
    DECLARE @CONTRACT_NUM VARCHAR(10); -- Contract Number. The value that will be updated on the table.
    DECLARE @CONTRACT INTEGER; -- Contract number, the auto increment section on contract number
    DECLARE @CONTR_ROW VARCHAR(200); -- Contract row. The row elements that will be using on cursor
    DECLARE CONTRACT_CURSOR CURSOR FOR -- Get the necessary fields from table
    SELECT PROPERTY_CODE, CUSTOMER, CUST_CATEGORY, AMNT
    FROM CONTRACTS;
    OPEN CONTRACT_CURSOR -- open a cursor
    FETCH NEXT FROM CONTRACT_CURSOR INTO @CONTR_ROW
    WHILE @@FETCH_STATUS = 0 -- execute the update, for every row of the tabl
    BEGIN
    --update Contract_Num, using the format coding : contract_number = 'CN' + 0001
    UPDATE CONTRACTS
    SET CONTRACT_NUM = 'CN'+@CONTRACT_NUM+1
    END
    CLOSE CONTRACT_CURSOR
    Thank you in advance!

    You dont need cursor
    You can simply use an update statement like this
    UPDATE t
    SET Contract_Num = 'CN' + RIGHT('00000' + CAST(Rnk AS varchar(5)),5)
    FROM
    SELECT Contract_Num,
    DENSE_RANK() OVER (ORDER BY Property_Code,Customer,Cust_category,Amnt) AS Rnk
    FROM table
    )t
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for

  • How to display a binary image in a webpage?

    Hi, I want to display a binary image in a webage. The image has been stored in a DB as binary format. I am using servlet. How could I retrieve it and display it on a webpage? Could you give me some suggestions? I have read some metrial about JAI, the

  • Blinded my new IMAC screen

    Can i dim the brightness on my 24 inch screen anymore?? Love the new computer, but need a pair of sunglasses, especially at night. Its bad enough during the day but im trying to wind down and go to sleep and its like ive got a spotlight in my face Ye

  • Ready to take a sledgehammer to my WRT110, anyone care to try to help?

    hey, i have a WRT110 and have been having tons of issues with it. i recently bought a motorola droid cell phone which has wifi. when i first tried connecting it to wifi when it connected it would kick every computer or device in the house off of the

  • No suitable communication component

    Hi, I am in Integration Builder (PI 7.1) and want to configure a communication component for my application component. I have several business systems defined in SLD but none of them actually have the product I defined in the application component ma

  • Question about "bluetooth PDA-syn" option?

    HI there, I would just like to ask under system preferences, under bluetooth, under advance, there is an option called "bluetooth pda-sync", in its box, should I check or uncheck this option? what is the option "bluetooth pda-sync" for? what is its u