Oracle 实现类似SQL Server中自增字段的一个办法
相关代码如下:
1. 创建sequence:
复制代码 代码如下:
CREATE SEQUENCE SEQU_DATA_DATAINFO INCREMENT BY 1 START WITH 1 NOCYCLE NOCACHE NOORDER;
2. 创建触发器:
复制代码 代码如下:
create or replace TRIGGER TRIG_TEST
BEFORE INSERT ON TABLE1
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
tmpVar := 0;
Select SEQU_PROC_ASSOCIATEINFO.NextVal into tmpVar from dual;
:new.procid:=tmpVar;
EXCEPTION
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END;
1. 创建sequence:
复制代码 代码如下:
CREATE SEQUENCE SEQU_DATA_DATAINFO INCREMENT BY 1 START WITH 1 NOCYCLE NOCACHE NOORDER;
2. 创建触发器:
复制代码 代码如下:
create or replace TRIGGER TRIG_TEST
BEFORE INSERT ON TABLE1
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
tmpVar := 0;
Select SEQU_PROC_ASSOCIATEINFO.NextVal into tmpVar from dual;
:new.procid:=tmpVar;
EXCEPTION
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END;
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
本文地址:/shujuku/oracle/100183.html