我收到了这个'留言'表。
CREATE TABLE message (
id INT PRIMARY KEY,
user_id INT NOT NULL REFERENCES users (id) ON DELETE CASCADE,
category_id INT NOT NULL REFERENCES category (id) ON DELETE CASCADE,
text VARCHAR2(4000),
media VARCHAR2(500),
creation_date DATE DEFAULT SYSDATE
);
CREATE SEQUENCE message_seq;
CREATE OR REPLACE TRIGGER message_bir
BEFORE INSERT ON message
FOR EACH ROW
BEGIN
SELECT message_seq.NEXTVAL
INTO :new.id
FROM dual;
END;
插入内容后,我需要最后插入的ID和日期。
INSERT INTO message (user_id, category_id, media)
VALUES (1, 1, 'fdsfsd')
RETURNING id INTO :last_insert_id
上面给了我最后插入的id,但就像我说我还需要creation_date。我不想在...之后做一个选择查询。
有没有办法在运行插入后获得2个值?
答案 0 :(得分:6)
你可以写:
RETURNING id, creation_date INTO :last_insert_id, :last_creation_date.
请参阅http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/returninginto_clause.htm