欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

判定一个字符串是否为有效时间的函数

程序员文章站 2023-11-17 19:35:28
判定一个字符串是否为有效时间的函数,为有效时间则返回1,不是有效时间则返回0. create or replace function is_date(parame...

判定一个字符串是否为有效时间的函数,为有效时间则返回1,不是有效时间则返回0.

create or replace function is_date(parameter varchar2) return number is
val date;
begin
val := to_date(nvl(parameter, 'a'), 'yyyy-mm-dd hh24:mi:ss');
return 1;
exception
when others then
return 0;
end;

具体例子,可以直接使用:

alter session force parallel ddl parallel 8;
create table tt as select t.id,
floor(months_between(sysdate,to_date(t.birthday,'yyyymmdd'))/12) age
from tt_wxtran t
where is_date(t.birthday)!=0;