Oracle中判断是否数字function:
- CREATE OR REPLACE FUNCTION ISNUMBER(MyStr VARCHAR2) RETURN NUMBER
- IS
- STR VARCHAR2(400);
- ISNUM NUMBER;
- NUM NUMBER;
- BEGIN
- --返回0,不是数字。1,是数字
- ISNUM:=0;
- STR:=TRIM(MyStr);
- --如果输入值为空,就返回不是数字。
- IF TRIM(STR) IS NOT NULL THEN
- BEGIN
- NUM:=TO_NUMBER(STR);
- ISNUM:=1;
- EXCEPTION
- WHEN INVALID_NUMBER THEN
- NULL;
- WHEN OTHERS THEN
- NULL;
- END;
- END IF;
- RETURN ISNUM;
- END;
触发器:
- create or replace trigger biufer_tbmeetmgr_CHANGETIME
- --after插入之后
- --before 插入之前
- before insert or update or delete
- on tbmeetmgr
- for each row
- declare
- TYPE c_time IS REF CURSOR; --创建游离标记
- vrec c_time;
- varInt number ;
- strOverSql varchar2(30);
- roomname varchar2(100);
- roomcnt number;
- v_usercount number;
- roomId varchar2(100); --会议室编号
- booleanStr varchar2(10); --判断是否数字返回值
- v_username varchar2(50);
- begin
- --调用存储过程
- if inserting then
- booleanStr := isnumber(:NEW.Huiyishi); --返回0为字符串、1为数字
- if booleanStr = 1 then
- roomId := :NEW.Huiyishi;
- select count(0) into roomcnt from tbmeetroom t where t.id = :NEW.Huiyishi;
- if roomcnt > 0 then
- select t.name into roomname from tbmeetroom t where t.id = :NEW.Huiyishi;
- end if;
- if roomcnt <= 0 then
- roomname := :NEW.Huiyishi;
- end if;
- end if;
- if booleanStr = 0 then
- roomId := 0;
- roomname := :NEW.Huiyishi;
- end if;
- select count(0) into v_usercount from tbsysuserinfo t where t.userid = :NEW.Creator;
- if v_usercount > 0 then
- select t.username into v_username from tbsysuserinfo t where t.userid = :NEW.Creator;
- end if;
- --一次性会议
- if :NEW.huiyimoshi = 1 then
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),:NEW.Stoptime,0,:NEW.ecid, :NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- end if;
- --单周会议
- varInt := 0;
- if :NEW.xunhuaimoshi = 1 then
- select ceil(( to_date(:NEW.Stoptime,'yyyy-mm-dd') - next_day(to_date(substr(:NEW.Createtime, 1, 10),'yyyy-mm-dd')-1, ceil(substr(:NEW.Xunhuairiqi,3)))+1 )/7) into varInt from dual;
- OPEN vrec for SELECT to_char(next_day(to_date(substr(:NEW.Createtime,1,10),'yyyy-mm-dd')-1,
- ceil(substr(:NEW.Xunhuairiqi,3)))+1+(rownum-1)*7 , 'yyyy-MM-dd')
- from dual connect by rownum<=varInt ;
- LOOP
- FETCH vrec INTO strOverSql; --入库终止日期
- exit when vrec%notfound;
- --dbms_output.put_line('----+++++单周循环日期++++++-----:'||strOverSql);
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),strOverSql,1,:NEW.ecid,:NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- -- commit;
- end loop;
- end if;
- --每月循环
- varInt := 0;
- if :NEW.xunhuaimoshi = 3 then
- select ceil(months_between(to_date(:NEW.stoptime,'yyyy-mm-dd'),
- to_date(substr(:NEW.createtime, 1, 10),'yyyy-mm-dd'))) into varInt from dual;
- OPEN vrec for SELECT to_char(add_months(to_date((substr(:NEW.createtime,1,8))||(substr(:NEW.Xunhuairiqi,3,4)),'yyyy-MM-dd'),+(rownum-1)), 'yyyy-mm-dd')
- from dual connect by rownum<= ceil(varInt) ;
- LOOP
- FETCH vrec INTO strOverSql; --入库终止日期
- exit when vrec%notfound;
- --dbms_output.put_line('月度时间:'||strOverSql);
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),strOverSql,3,:NEW.ecid,:NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- -- commit;
- end loop;
- end if;
- --季度循环
- varInt := 0;
- if :NEW.xunhuaimoshi = 4 then
- select ceil((to_date(:NEW.stoptime,'yyyy-mm-dd')-to_date(substr(:NEW.createtime, 1, 10),'yyyy-mm-dd'))/90)
- into varInt from dual;
- OPEN vrec for SELECT to_char(add_months(to_date((substr(:NEW.createtime,1,5))||(substr(:NEW.Xunhuairiqi,3,7)),'yyyy-MM-dd'),+(rownum-1)*3), 'yyyy-mm-dd')
- from dual connect by rownum<= ceil(varInt) ;
- LOOP
- FETCH vrec INTO strOverSql; --入库终止日期
- exit when vrec%notfound;
- --dbms_output.put_line('月度时间:'||strOverSql);
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),strOverSql,4,:NEW.ecid,:NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- -- commit;
- end loop;
- end if;
- end if;
- if deleting then
- delete from tbmeetmgrinfo t where t.mid = :OLD.Id;
- end if;
- if updating then
- delete from tbmeetmgrinfo t where t.mid = :OLD.Id;
- booleanStr := isnumber(:NEW.Huiyishi);
- if booleanStr = 1 then
- roomId := :NEW.Huiyishi;
- select count(0) into roomcnt from tbmeetroom t where t.id = :NEW.Huiyishi;
- if roomcnt > 0 then
- select t.name into roomname from tbmeetroom t where t.id = :NEW.Huiyishi;
- end if;
- if roomcnt <= 0 then
- roomname := :NEW.Huiyishi;
- end if;
- end if;
- if booleanStr = 0 then
- roomId := 0;
- roomname := :NEW.Huiyishi;
- end if;
- select count(0) into v_usercount from tbsysuserinfo t where t.userid = :NEW.Creator;
- if v_usercount > 0 then
- select t.username into v_username from tbsysuserinfo t where t.userid = :NEW.Creator;
- end if;
- --一次性会议
- if :NEW.huiyimoshi = 1 then
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),:NEW.Stoptime,0,:NEW.ecid, :NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- end if;
- --单周会议
- varInt := 0;
- if :NEW.xunhuaimoshi = 1 then
- select ceil(( to_date(:NEW.Stoptime,'yyyy-mm-dd') - next_day(to_date(substr(:NEW.Createtime, 1, 10),'yyyy-mm-dd')-1, ceil(substr(:NEW.Xunhuairiqi,3)))+1 )/7) into varInt from dual;
- OPEN vrec for SELECT to_char(next_day(to_date(substr(:NEW.Createtime,1,10),'yyyy-mm-dd')-1,
- ceil(substr(:NEW.Xunhuairiqi,3)))+1+(rownum-1)*7 , 'yyyy-MM-dd')
- from dual connect by rownum<=varInt ;
- LOOP
- FETCH vrec INTO strOverSql; --入库终止日期
- exit when vrec%notfound;
- --dbms_output.put_line('----+++++单周循环日期++++++-----:'||strOverSql);
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),strOverSql,1,:NEW.ecid,:NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- -- commit;
- end loop;
- end if;
- --每月循环
- varInt := 0;
- if :NEW.xunhuaimoshi = 3 then
- select ceil(months_between(to_date(:NEW.stoptime,'yyyy-mm-dd'),
- to_date(substr(:NEW.createtime, 1, 10),'yyyy-mm-dd'))) into varInt from dual;
- OPEN vrec for SELECT to_char(add_months(to_date((substr(:NEW.createtime,1,8))||(substr(:NEW.Xunhuairiqi,3,4)),'yyyy-MM-dd'),+(rownum-1)), 'yyyy-mm-dd')
- from dual connect by rownum<= ceil(varInt) ;
- LOOP
- FETCH vrec INTO strOverSql; --入库终止日期
- exit when vrec%notfound;
- --dbms_output.put_line('月度时间:'||strOverSql);
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),strOverSql,3,:NEW.ecid,:NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- -- commit;
- end loop;
- end if;
- --季度循环
- varInt := 0;
- if :NEW.xunhuaimoshi = 4 then
- select ceil((to_date(:NEW.stoptime,'yyyy-mm-dd')-to_date(substr(:NEW.createtime, 1, 10),'yyyy-mm-dd'))/90)
- into varInt from dual;
- OPEN vrec for SELECT to_char(add_months(to_date((substr(:NEW.createtime,1,5))||(substr(:NEW.Xunhuairiqi,3,7)),'yyyy-MM-dd'),+(rownum-1)*3), 'yyyy-mm-dd')
- from dual connect by rownum<= ceil(varInt) ;
- LOOP
- FETCH vrec INTO strOverSql; --入库终止日期
- exit when vrec%notfound;
- --dbms_output.put_line('月度时间:'||strOverSql);
- insert into tbmeetmgrinfo values(tbmeetmgrinfo_tb_sequence.nextval,roomId,:NEW.Starttime,:NEW.Endtime,substr(:NEW.Createtime,1,10),strOverSql,4,:NEW.ecid,:NEW.Id,:NEW.TONGZHIFANGSHI,:NEW.TONGZHISHIJIAN,roomname,:NEW.ZHUTI,:NEW.Meetno,:NEW.Creator,v_username);
- -- commit;
- end loop;
- end if;
- end if;
- end;