oracle写一个触发器,一个关于日期的触发器该怎么写?

练练手,不对的地方请大家指出:

create table test(start_time date,end_time date,gay_time varchar2(50),fromtoweek varchar2(50));

create or replace procedure proc_test(v_start_time date,v_end_time date)

as

invalid_time_exception exception;

gap_time number;

week_day varchar2(100);

begin

if v_start_time is null or v_end_time is null then

raise invalid_time_exception;

else

select trunc(v_end_time-v_start_time,2) into gap_time from dual;

if  gap_time>=1 then

select to_char(v_start_time,'day')||'--'||to_char(v_end_time,'day') into week_day from dual;

insert into test values(v_start_time,v_end_time,gap_time||'(天)',week_day);

else

if substr(to_char(v_start_time),1,8)=substr(to_char(v_end_time),1,8) then

select to_char(v_start_time,'day') into week_day from dual;

insert into test values(v_start_time,v_end_time,gap_time*24||'(小时)',week_day);

else

select to_char(v_start_time,'day')||'--'||to_char(v_end_time,'day') into week_day from dual;

insert into test values(v_start_time,v_end_time,gap_time*24||'(小时)',week_day);

end if;

end if;

end if;

commit;

dbms_output.put_line('procedure successful');

exception

when invalid_time_exception then

dbms_output.put_line('time inputed is invalid');

when others then

dbms_output.put_line(sqlcode||sqlerrm);

end proc_test;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值