CREATE TABLE test_table
(
ID NUMBER NOT NULL,
ID_COMPANY VARCHAR2(20 BYTE)
)
Table created.
CREATE SEQUENCE test_sequence
START WITH 1
INCREMENT BY 1;
Sequence created.
CREATE OR REPLACE TRIGGER test_trigger
BEFORE INSERT
ON test_table
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT test_sequence.nextval INTO :NEW.ID FROM dual;
END;
/
Trigger created.
Now, test adding sample data
1 row created.SQL> INSERT INTO test (
ID_COMPANY) VALUES ('ABC123');
ps : Oracle is sucks. MySQL is sexy!
No comments:
Post a Comment