Re: Simple Pro/C Question

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 1998/09/06
Message-ID: <35f695ae.3316248_at_192.86.155.100>#1/1


A copy of this was sent to kim_at_kiml.demon.co.uk (Kim Limbrick) (if that email address didn't require changing) On Sun, 06 Sep 1998 08:24:21 GMT, you wrote:

>On Fri, 04 Sep 1998 13:15:40 GMT, tkyte_at_us.oracle.com (Thomas Kyte)
>wrote:
>>
>>use TO_CHAR() on the date field with the format mask you want, for example
>>
>>
>>void process( int rows )
>>{
>>EXEC SQL BEGIN DECLARE SECTION;
>>VARCHAR str[512];
>>EXEC SQL END DECLARE SECTION;
>>
>> EXEC SQL
>> SELECT TO_CHAR( SYSDATE, 'DD-MON-YYYY' ) INTO :str
>> FROM DUAL;
>>
>> printf( "%.*s\n", str.len, str.arr );
>>}
>>
>>
>>$ ./test
>>04-SEP-1998
>>.............
>>
>
>Thomas,
>
>Thanks for your help the SQL above works really well. I was wondering
>if there are any functions I could call to do a simialr job. In some
>situations I want to do the date formatting after the data has been
>retrieved.
>
>Regards

You want to use the TO_DATE() function in your C code. In order to do that, you need to goto the server. Lets say you have selected some date field into your code, you the user entered one. In any case, you have a C string with the data dd/mm/yyyy hh:mi:ss am. You would like it formatted differently. the following code will do that:

void process(void )
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR str[512];
EXEC SQL END DECLARE SECTION;     strcpy( str.arr, "03/15/1965 03:23:44 am" );     str.len = strlen( str.arr );

    EXEC SQL

     SELECT to_char( to_date( :str, 'mm/dd/yyyy hh:mi:ss AM' ), 'DD-MON-YYYY' )
        into :str
        from dual;

    printf( "%.*s\n", str.len, str.arr ); }

You need to go back to the database to use TO_DATE() in Pro*C but you can take a string that was in one format, and easily to_date() that and then to_char() the results...

So, select the date out in any format you want and then you can convert it later when you want to...  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA

--
http://govt.us.oracle.com/    -- downloadable utilities
 
----------------------------------------------------------------------------
Opinions are mine and do not necessarily reflect those of Oracle Corporation
 
Anti-Anti Spam Msg: if you want an answer emailed to you, 
you have to make it easy to get email to you.  Any bounced
email will be treated the same way i treat SPAM-- I delete it.
Received on Sun Sep 06 1998 - 00:00:00 CEST

Original text of this message