ansi sql
Posted in 1999
Topics: Data Types & Schema Design
hi, I'm just starting with Informix (v. 7.3), and got a few questions. 1. is there a predefinied function to check if the value of variable is a date? is there a predefinied function to check if the value of variable is decimal? assume, that in both cases variables are declared as a VARCHAR. 2. is a easy and cheap way to convert VARCHAR to DEC (predefinied function). cause, there's a function: Date(VARCHAR) returning DATE all the best CN
CN wrote:
> I'm just starting with Informix (v. 7.3), and got a few questions.
>
> 1. is there a predefinied function to check if the value of variable
> is a date?
> is there a predefinied function to check if the value of variable
> is decimal?
>
> assume, that in both cases variables are declared as a VARCHAR.
I don't think so. In either case, it is not desparately hard to write
a stored procedure to do the job, though handling the error on a failed
conversion requires some management. Also, do you want the converted
date/decimal as the returned value, with NULL on failure, or something
else?
-- untested code --
CREATE PROCEDURE is_date(v VARCHAR(30)) RETURNING DATE; DEFINE d DATE;
ON EXCEPTION
RETURN NULL;
END EXCEPTION
LET d = v;
RETURN d;
END PROCEDURE;
With 7.3, the TO_DATE() function may do what you need -- my 5.00 manual
doesn't cover that.
> 2. is a easy and cheap way to convert VARCHAR to DEC (predefinied
> function).
> cause, there's a function: Date(VARCHAR) returning DATE
The analogue of the is_date() function above is easy enough to
use. Also, a lot of the time you can simply get away with:
str + 0.0
--
Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net)
Guardian of DBD::Informix v0.62 -- see http://www.perl.com/CPAN
#include <disclaimer.h>