Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Need function "is_date" for converting varchar2 to date-format

Re: Need function "is_date" for converting varchar2 to date-format

From: x <x_at_x.hr>
Date: Wed, 26 May 2004 12:49:25 +0200
Message-ID: <c91sl8$6jt$1@ls219.htnet.hr>


> I *think* I would write is_date as
>
> create or replace function is_date(dt IN varchar2,fmt IN varchar2) return
> number
> is
> d date;
> begin
> d := to_date(dt,fmt);
> return 1;
> exception
> when others
> return 0;
> end;
> /
>
> where dt is the string and fmt a valid date format.

Why return 1 or 0? Why not returning the date itself? This way you'll have to write your queries like this:

select my_date from my_table where is_date(my_date,fmt)=1 union
select null from my_table where is_date(my_date,fmt)=0

or something like this.

just change the cod above to:

create or replace function is_date(dt IN varchar2,fmt IN varchar2) return  date
 is
 d date;
 begin
 d := to_date(dt,fmt);
 return d;
 exception

     when others
         return null;

 end;

and you have:

select is_date(my_date,fmt) from my_table Received on Wed May 26 2004 - 05:49:25 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US