gpt4 book ai didi

sql - Oracle 中插入后触发插入 sysdate

转载 作者:行者123 更新时间:2023-12-01 23:47:38 24 4
gpt4 key购买 nike

我尝试使用以下命令,但显然它是无效的 SQL:

CREATE OR REPLACE TRIGGER QUESTION_DATE BEFORE INSERT ON QUESTION 
FOR EACH ROW
BEGIN
INSERT INTO QUESTION(CREATED_TIMESTAMP)
VALUES (SYSDATE);
END;

到目前为止,问题表如下所示:

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;

如果相关,我正在使用 Toad for Oracle V9.0.1.8

最佳答案

不要使用触发器在 Oracle 中设置默认值。相反,请在列上使用“DEFAULT”。这是一个示例列

CREATED_TIMESTAMP  TIMESTAMP  DEFAULT SYSDATE  NOT NULL,

关于sql - Oracle 中插入后触发插入 sysdate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4248243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com