Oracle中的有效日期检查

vve*_*lva 4 oracle date

我有一个varchar格式的日期值(有效日期或无效日期)商店.是否可以在sql查询中检查日期是否有效.

Flo*_*ita 7

是的,如果你知道格式和plsql很少.

假设您的格式为日期'yyyy-mon-dd hh24:mi:ss'.

create function test_date(d varchar2) return varchar2
is
  v_date date;
begin
  select to_date(d,'yyyy-mon-dd hh24:mi:ss') into v_date from dual;
  return 'Valid';
  exception when others then return 'Invalid';
end;
Run Code Online (Sandbox Code Playgroud)

现在你可以:

select your_date_col, test_date(your_date_col)
from your_table;
Run Code Online (Sandbox Code Playgroud)