A function of determining whether a string is valid or not

  • 2021-12-12 06:11:49
  • OfStack

A function that determines whether a string is a valid time, which returns 1 if it is valid, and 0 if it is not valid.


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;

Specific examples can be directly used:


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;

Related articles: