I am attempting Autonumber the records in Oracle Table
ID is primary key
When I insert a new row, I want the new row to have the next sequential number.
old row ID = 100
new row ID (is to = 101) before insert
In creating a trigger the following code gets generated.
CREATE OR REPLACE TRIGGER DOBS.my_trigger1
BEFORE INSERT
ON DOBS.LK_PRODUCT_NDC_MAPPING
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
tmpVar NUMBER;
/******************************************************************************
NAME:
PURPOSE:
REVISIONS:
Ver Date Author Description
1.0 8/11/2017 1. Created this trigger.
NOTES:
Automatically available Auto Replace Keywords:
Object Name:
Sysdate: 8/11/2017
Date and Time: 8/11/2017, 12:06:08 PM, and 8/11/2017 12:06:08 PM
Username: (set in TOAD Options, Proc Templates)
Table Name: LK_PRODUCT_NDC_MAPPING (set in the “New PL/SQL Object” dialog)
Trigger Options: (set in the “New PL/SQL Object” dialog)
******************************************************************************/
BEGIN
tmpVar := 0;
SELECT MySeq.NEXTVAL INTO tmpVar FROM dual;
:NEW.SequenceColumn := tmpVar;
:NEW.CreatedDate := SYSDATE;
:NEW.CreatedUser := USER;
EXCEPTION
WHEN OTHERS THEN
– Consider logging the error and then re-raise
RAISE;
END ;
QUESTION: Do I edit the code change SequenceColumn to ID?
It appears that this has to be edit and then saved.
I don’t need to update the other fields. Those appear to be “examples”.
Could someone confirm this?
Thanks.
JayGBardo1