to_date 就可以了 不对会报错的 比如你这种情况就会报越界 没有14月 的或者if substr(col,6,2)<13 then插入; end if;
-- oracle 10 正则表达式验证(1900/01/01 - 2011/12/31) -- 缺点:无法验证月大月小 with t as ( select '2000/12/31' dt from dual union all select '2001/13/01' from dual union all select '2011/01/40' from dual) select dt from t where regexp_like(dt,'(19[0-9]{2}|20(0[0-9]|1[01]))/(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])') /
如果是date的类型的话 oracle会自动帮你判断的
可能是nvarchar()如果是nvarchar()怎么办啊。
因为我这次是要把数据通过EXCEL导到 中间表,然后再从中间表导到正式表。
我就想在配信息的时候,通过SQL语句判断,日期是否正确。日期格式我想到判断的方法了,就是不知道该怎么判断日期是否正确。
end if;
-- oracle 10 正则表达式验证(1900/01/01 - 2011/12/31)
-- 缺点:无法验证月大月小
with t as (
select '2000/12/31' dt from dual
union all
select '2001/13/01' from dual
union all
select '2011/01/40' from dual)
select dt from t
where regexp_like(dt,'(19[0-9]{2}|20(0[0-9]|1[01]))/(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])')
/
在块里去做to_date转换,exception里处理错误情况就可以了
to_date 就可以了 不对会报错的 比如你这种情况就会报越界 没有14月 的 加个异常快
SQL> ed
已写入 file afiedt.buf 1 declare
2 type t__tbl is table of varchar2(20);
3 dt_arr t__tbl:=t__tbl('2010/04/11','2010/14/11','2010/12/11');
4 begin
5 execute immediate 'create table tb_dterr(dt date)';
6 for i in 1..dt_arr.count loop
7 begin
8 execute immediate 'insert into tb_dterr values(to_date('''||dt_arr(i)||''',''yyyy/mm/dd''))';
9 commit;
10 dbms_output.put_line(to_date(dt_arr(i),'yyyy/mm/dd'));
11 exception
12 when others then
13 null;
14 end;
15 end loop;
16* end;
SQL> /
2010/04/11
2010/12/11PL/SQL 过程已成功完成。SQL> select * from tb_dterr
2 /DT
----------
2010/04/11
2010/12/11