Oracle 생 성 시퀀스 트리거
1561 단어 Oacle
declare
num number;
begin
-- prompt dropping sequence
num := 0;
select count(1) into num from user_sequences where sequence_name = 'COMMON_MYTASK_SEQUENCE';
if num > 0 then
execute immediate 'DROP SEQUENCE COMMON_MYTASK_SEQUENCE';
end if;
-- prompt dropping trigger
num := 0;
select count(1) into num from user_triggers where trigger_name = 'COMMON_MYTASK_TG';
if num > 0 then
execute immediate 'DROP TRIGGER COMMON_MYTASK_TG';
end if;
-- prompt Dropping
num := 0;
select count(1) into num from user_tables where TABLE_NAME = 'T_COMMON_MYTASK';
if num=1 then
execute immediate 'drop table T_COMMON_MYTASK';
end if;
end;
/
--
CREATE TABLE T_COMMON_MYTASK(
id NUMBER NOT NULL,
process_definition_id varchar2(100) not null,-- id
request_staff_id number not null,-- id
approver_id number not null,-- id
process_type number not null,-- : ; ;....
crt_time date,--
CONSTRAINT PK_T_COMMON_MYTASK PRIMARY KEY ("ID")
);
--create sequence
create sequence COMMON_MYTASK_SEQUENCE
start with 1
increment by 1
nomaxvalue
nocycle
cache 20;
-- create trigger
CREATE OR REPLACE TRIGGER COMMON_MYTASK_TG
BEFORE INSERT ON T_COMMON_MYTASK
FOR EACH ROW
WHEN (new.id is null)
begin
select COMMON_MYTASK_SEQUENCE.nextval into :new.id from dual;
end COMMON_MYTASK_TG;
/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 작업 은 Clob 또는 NClob 데이터 형식의 저장 프로 세 스 인 스 턴 스 를 포함 합 니 다.텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.