好象没有现成的函数,你可以在存储过程里判断呀。len(a)要个判断,substring( a, 5,2) >12 ot not.
oracle里有这样的函数吗? 要不,得自己写一个合法日期判断吧。
SQL> select to_date('200314','yyyymm') from dual; select to_date('200314','yyyymm') from dual * ERROR 位于第 1 行: ORA-01843: 无效的月份在plsql中利用异常处理机制可以实现的。
用PL/SQL异常出来来判断: begin select TO_DATE( my_rq, 'yyyymmdd' ) INTO rq from dual; EXCEPTION when others then raise_application_error( -20218, '日期格式不对my_rq='||my_rq||' ,正确格式 YYYYMMDD' ); END;
可以用to_date通过异常来判断, 也可以在应用程序中做限制。
create function is_date(p_date in varchar2) return number as a date; begin a:=to_date(p_date,'yyyymm'); return 1; exception when others then return 0; end; / select * from table_name where is_date(col_date)=1;
result_date date; begin select result_date = to_date(input_date, 'yyyymm' );exception when others then //format error end;
要不,得自己写一个合法日期判断吧。
select to_date('200314','yyyymm') from dual
*
ERROR 位于第 1 行:
ORA-01843: 无效的月份在plsql中利用异常处理机制可以实现的。
begin
select TO_DATE( my_rq, 'yyyymmdd' ) INTO rq from dual;
EXCEPTION
when others then
raise_application_error( -20218, '日期格式不对my_rq='||my_rq||' ,正确格式 YYYYMMDD' );
END;
也可以在应用程序中做限制。
return number
as
a date;
begin
a:=to_date(p_date,'yyyymm');
return 1;
exception
when others then
return 0;
end;
/
select * from table_name where is_date(col_date)=1;
begin
select result_date = to_date(input_date, 'yyyymm' );exception
when others then
//format error
end;