I tried using the following but apparently it's invalid SQL:
CREATE OR REPLACE TRIGGER QUESTION_DATE BEFORE INSERT ON QUESTION
FOR EACH ROW
BEGIN
INSERT INTO QUESTION(CREATED_TIMESTAMP)
VALUES (SYSDATE);
END;
The Question table looks like this so far:
CREATE TABLE QUESTION
(
QUESTION_ID INTEGER not null,
LATEST_QUESTION INTEGER not null,
CREATED_USER_ID INTEGER not null,
CREATED_TIMESTAMP TIMESTAMP not null,
CONSTRAINT PK_QUESTION PRIMARY KEY (QUESTION_ID)
);
CREATE SEQUENCE QUESTION_ID_SEQ INCREMENT BY 1 START WITH 1 NOCYCLE NOCACHE NOORDER;
CREATE TRIGGER QUESTION_INSERT BEFORE INSERT ON QUESTION
FOR EACH ROW
BEGIN
SELECT QUESTION_ID_SEQ.nextval
INTO :new.QUESTION_ID
FROM dual;
END;
I'm using Toad for Oracle V9.0.1.8 if that's relevant
First, we will specify the name of the trigger that we want to create. It should be unique within the schema. Second, we will specify the trigger action time, which should be AFTER INSERT clause to invoke the trigger. Third, we will specify the name of a table to which the trigger is associated.
The database server allows triggers other than Select triggers to cascade, meaning that the trigger actions of one trigger can activate another trigger. (For further information on the restriction against cascading Select triggers, see Circumstances When a Select Trigger Is Activated.)
Dont use a trigger to set a default value in Oracle. Instead, use "DEFAULT" on the column. Here is an exmple column
CREATED_TIMESTAMP TIMESTAMP DEFAULT SYSDATE NOT NULL,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With