Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Simple Pro*C FETCH Question
naren,
VARCHAR2 is what you want to use (In version 7 VARCHAR should also work, I'm not sure about version 8). However, when using VARCHAR or VARCHAR2 Oracle does not NULL terminate the string for you. It provides you with the length of the string, but you must NULL terminate it yourself. Here is an example.
VARCHAR2 emp_name[12];
VARCHAR2 emp_title[20];
EXEC SQL FETCH emp_cursor INTO :emp_name, :emp_title;
if (sqlca.sqlcode != 0)
{
Display message, close cursor and return. }
// NULL terminate the strings
emp_name.arr[emp_name.len] = 0x00;
emp_title.arr[emp_title.len] = 0x00;
Now emp_name.arr should contain 'JOHN DOE'. This is assuming of course that it was not originally stored in the database with the blanks. If it was, then you need to either correct this in the database or use the Oracle RTRIM function to remove the blanks.
Hope this helps,
Michael Twaddell
naren.dasu_at_divatv.com wrote:
>
> Hi all,
> This is my problem :-
>
> char emp_name[12];
> char emp_title[20];
>
> EXEC SQL FETCH emp_cursor INTO :emp_name, :emp_title ;
>
> I always get a blank-padded, null terminated emp_name and emp_title. For
> example I get
> emp_name ='JOHN DOE ' .
>
> How can I get rid of the trailing blanks ? ** I dont want to use strtok().
>
> Defining emp_name to be VARCHAR does not seem to work.
>
> thanks in advance
> naren
>
--
Michael Twaddell
Raytheon Systems
twaddell_at_ti.com
Received on Thu Apr 16 1998 - 06:31:45 CDT
![]() |
![]() |