我制作了一张桌子和四个序列。 (列的一个序列,列的三个序列。)
CREATE TABLE abc (
whole_number VARCHAR2(100) primary key,
board_number VARCHAR2(100),
board VARCHAR2(100),
content VARCHAR2(100)
);
CREATE SEQUENCE whole_seq
MINVALUE 1
NOMAXVALUE
INCREMENT BY 1 START WITH 1
;
CREATE SEQUENCE notify_seq
MINVALUE 1
NOMAXVALUE
INCREMENT BY 1 START WITH 1
;
CREATE SEQUENCE product_seq
MINVALUE 1
NOMAXVALUE
INCREMENT BY 1 START WITH 1
;
CREATE SEQUENCE guide_seq
MINVALUE 1
NOMAXVALUE
INCREMENT BY 1 START WITH 1
;
我想创建一个在每行为whole_number列添加whole_seq的过程, 如果board列获得'guide',则为board_number列的guide_seq和guide_seq。 如果board列获得'notify',则发送给board_number列的notify_seq。
现在制作了一个full_number列的程序。
CREATE OR REPLACE TRIGGER whole_number_trigger
BEFORE INSERT
ON abc FOR EACH ROW
BEGIN
SELECT whole_seq INTO :new.whole_number FROM dual;
END;
/
有人可以根据ORACLE中的Board列值来帮助我创建一个不同序列的过程吗? 另外,有没有办法在full_number列的序列号之前添加字符串'Board_'?
答案 0 :(得分:4)
CREATE OR REPLACE TRIGGER whole_number_trigger
BEFORE INSERT
ON abc FOR EACH ROW
BEGIN
SELECT 'Board_' || whole_seq.nextval INTO :new.whole_number FROM dual;
IF :new.board = 'guide' THEN
SELECT guide_seq.nextval INTO :new.board_number FROM dual;
ELSIF :new.board = 'notify' THEN
SELECT notify_seq.nextval INTO :new.board_number FROM dual;
END IF;
END;
/