使用触发器创建序列
!--說(shuō)明:藥師職稱管理觸發(fā)器
declare
v_MaxId number;
v_sql varchar2(2000);
v_ExistSequence number;
begin
Select Count(*) into v_ExistSequence from USER_OBJECTS WHERE OBJECT_TYPE='SEQUENCE' AND Object_Name = upper('seq_FDAPharmacistType');
if v_ExistSequence = 1 then
execute immediate 'drop sequence seq_FDAPharmacistType';
end if;
select Max(iPharmacistTypeID) into v_MaxId from FDAPharmacistType;
if v_MaxId is null or v_MaxId = '' then
v_MaxId := 1;
else
v_MaxId := v_MaxId + 1;
end if;
v_sql := 'create sequence seq_FDAPharmacistType INCREMENT BY 1 START WITH '||to_Char(v_MaxId);
execute immediate v_sql;
v_sql := 'create or replace trigger trg_FDAPharmacistType' || CHR(10);
v_sql := v_sql || 'before insert on FDAPharmacistType' || CHR(10);
v_sql := v_sql || 'for each row' || CHR(10);
v_sql := v_sql || 'begin' || CHR(10);
v_sql := v_sql || ' select seq_FDAPharmacistType.nextval into :new.iPharmacistTypeID' || CHR(10);
v_sql := v_sql || ' from dual;' || CHR(10);
v_sql := v_sql || 'end trg_FDAPharmacistType;' || CHR(10);
execute immediate v_sql;
end;
轉(zhuǎn)載于:https://www.cnblogs.com/gaowenbin/articles/1856831.html
總結(jié)
- 上一篇: 百度前端技术交流会
- 下一篇: 国内企业应如何实施ITSM