oracle 触发器输出值,Oracle表触发器并写入序列值

--创建 序列 seq_1

drop sequence seq_1;

create sequence seq_1

minvalue 1

maxvalue 999999999999999999999999999

start with 100000000000000

increment by 1

nocache;

drop table test_Depart;

create table test_Depart (

did varchar2(32) not null primary key,

dname varchar2(32) not null

);

--建解发器代码为

create or replace trigger tri_test_id

before insert on test_Depart --test_Depart 是表名

for each row

declare

nextid varchar2(32);

begin

IF :new.did IS NULL or :new.did=0 THEN --did是列名

--取得年度

select to_char(sysdate,'yyyy')||seq_1.nextval

into nextid

from sys.dual;

:new.did:=nextid;

end if;

end tri_test_id;

-- for test

--select to_char(sysdate,'yyyy')||seq_1.nextval from dual;

--insert into test_Depart(dname) values('部门1');

或者

--建解发器代码为

create or replace trigger tri_test_id

before insert on test_Depart --test_Depart 是表名

for each row

declare

nextid number;

begin

IF :new.did IS NULL or :new.did=0 THEN --did是列名

select seq_1.nextval

into nextid

from sys.dual;

:new.did:=nextid;

end if;

end tri_test_id;

或者

--建解发器代码为

create or replace trigger tri_test_id

before insert on test_Depart --test_Depart 是表名

for each row

declare

nextid number;

begin

IF :new.did IS NULL or :new.did=0 THEN --did是列名

select to_number(to_char(sysdate,'yyyymmddHH24miss'))

into nextid

from sys.dual;

:new.did:=nextid;

end if;

end tri_test_id;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值