Use below function to convert any of your String type date values into Date values.
create or replace function str_to_date(p_str varchar2) return date is
type format_masks is table of varchar2(20);
begin
for i in 1 .. v_mask.count
loop
begin
v_date := to_date(p_str,v_mask(i));
return v_date;
exception
when others then null;
end;
end loop;
return null;
end;
examples
create or replace function str_to_date(p_str varchar2) return date is
type format_masks is table of varchar2(20);
v_mask
format_masks :=
format_masks('dd/mm/yyyy',
'dd-mon-yyyy',
'dd/mon/rr',
'dd@mm@yy',
'dd-mon@yy',
'ddmmyy',
'ddmonyy');
v_date
date;'dd-mon-yyyy',
'dd/mon/rr',
'dd@mm@yy',
'dd-mon@yy',
'ddmmyy',
'ddmonyy');
begin
for i in 1 .. v_mask.count
loop
begin
v_date := to_date(p_str,v_mask(i));
return v_date;
exception
when others then null;
end;
end loop;
return null;
end;
select str_to_date('01-jan-12') DATE_TEST from dual;
DATE_TEST --------- 01-JAN-12 select str_to_date('01-jan@12') DATE_TEST from dual;
DATE_TEST --------- 01-JAN-12
No comments:
Post a Comment