加入收藏
首页
关于我们
新闻动态
服务领域
解决方案
经典案例
技术文章
联系我们
您现在所在的位置:
主页
>
技术文章
>
ORACLE
>
ORACLE
Oracle表触发器并写入序列值
来源:未知 作者:admin 人气:
时间:2014-02-07
Java代码
--创建 序列 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'
);
或者
Java代码
--建解发器代码为
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;
或者
Java代码
--建解发器代码为
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;
上一篇:没有了
下一篇:
Oracle 查询锁表和解锁
三九手机网
昆明强川科技
云南蓝队网络
关于我们
新闻动态
服务领域
解决方案
经典案例
技术文章
联系我们
公司地址:昆明市高新区科华路1-19号山灞大厦主楼9楼 邮编:650000
手机:13759502558 传真:0871-63568770
Copyright © 2012-2020 ynits.com 云南IT服务中心 版权所有 滇ICP备13000495号-1