Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Comparing "date" values in Pro*C
Pravin Sitaram wrote:
>
> Hello,
>
> Within a Pro*C program, I need to select "date" values
> from a database table. What is the data type that I
> need to define in "C" for the host variable so that
> I can extract the "date" value into the host variable
> and then compare two "date" values? I tried "char *"
> datatype for the host variable, but it does not work.
>
> Please mail your suggestions to:
> nagaraj_jyothi_at_isus.emc.com
>
> Thanks,
> Jyothi
> --------------------------------------------------------------
Define your date avriables in C as char[15]. Then in SQL use the to_char function with a mask of 'yyyymmddhh24miss'.
void main()
{
EXEC SQL BEGIN DECLARE SECTION;
char date1[15];
EXEC SQL VAR date1 IS STRING;
char date2[15];
EXEC SQL VAR date2 IS STRING;
. . .
EXEC SQL END DECLARE SECTION;
EXEC SQL
SELECT TO_CHAR(d1,'YYYYMMDDHH24MISS'), TO_CHAR(d2,'YYYYMMDDHH24MISS') INTO :date1, date2 FROM table;
/* date1 > date2 */
}
else if (strcmp(date1,date2) < 0)
{
/* date1 < date2 */
}
else
{
/* dates are equal */
}
}
Hope this helps
Ken Denny
kendenny_at_bnr.ca (work)
kdenny_at_interpath.com (home)
Received on Tue Oct 07 1997 - 00:00:00 CDT