CREATE TABLE "Brand_relation"
(
"ID" number (10,0) is not NULL ENABLE,
"CATID" number (10,0) is not NULL ENABLE,
"brand_id" number (10,0) is not NULL ENABLE,
PRIMARY KEY ("ID")
);
CREATE SEQUENCE "Br_id_seq" NOCACHE;
CREATE INDEX "Br_catid" On "Brand_relation" ("CATID");
CREATE INDEX "br_brand_id" On "Brand_relation" ("brand_id");
CREATE OR REPLACE TRIGGER ' BR_ID_TRG ' before INSERT on ' brand_relation ' referencing old as ' old ' new as ' new ' for each ROW ENABLE
DECLARE
V_newval Number (12): = 0;
V_incval Number (12): = 0;
BEGIN
IF INSERTING AND:new.id is NULL then
SELECT Br_id_seq. Nextval to V_newval from DUAL;
-If This is the first time this table has been inserted into (sequence = = 1)
IF V_newval = 1 Then
--get the max indentity value from the table
SELECT NVL (max (ID), 0) into V_newval from Brand_relation;
V_newval: = V_newval + 1;
--set the sequence to that value
LOOP
EXIT when v_incval>=v_newval;
SELECT Br_id_seq.nextval to v_incval from dual;
END LOOP;
END IF;
--used to emulate last_insert_id ()
--mysql_utilities.identity: = V_newval;
--Assign the value from the sequence to emulate the identity column
: new.id: = V_newval;
END IF;
END;
To create an Oracle data representation SQL