2013-8-6 10:56:07 JAVA_WEB:员工号自动生成源代码

 

create table user_info_temp
(
      usId varchar2(20),
      usNo varchar2(20),
      usName varchar2(50)
)


--oracle中如何查看当前系统时间
select sysdate from dual;

--oracle中获取当前指定显示系统时间:yyyy 年份
select to_char(sysdate,'yyyy') from dual;

--concat拼接:'T'+'年份'
select concat('T', to_char(sysdate,'yyyy')) from dual;

--查看序列号
select temp_seq.nextval from dual;


--创建触发器
create or replace trigger user_trg
before insert on user_info_temp for each row
when(new.usId is null)--(new.usId is null or/and new.usNo is null)
declare      
              pk number;
begin   
              select temp_seq.nextval into pk from dual;
              select pk into :new.usId from dual;
              select concat(concat('T', to_char(sysdate,'yyyy')),lpad(pk,4,'0')) into :new.usNo from dual;
end;             
      
 
--测试触发器是创建成功
insert into user_info_temp(usId,usNo,usName) values ('1','T001','小强') ;
insert into user_info_temp(usId,usNo,usName) values ('1','T001','小李') ;
insert into user_info_temp(usName) values ('小李2') ;
select * from user_info_temp;


--说明:创建序列
-- Create sequence
create sequence TEMP_SEQ
minvalue 1
maxvalue 9999999999
start with 11
increment by 1
cache 10;

 

 

你可能感兴趣的:(java)