Re: Pro*C - extra space after variables

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 17 Dec 1999 08:26:28 -0500
Message-ID: <pdek5scevlkpd3geksvf5s51r16220ilrb_at_4ax.com>


A copy of this was sent to cjeastwd_at_powerup.com.au (Clint Eastwood) (if that email address didn't require changing) On Fri, 17 Dec 1999 04:09:34 GMT, you wrote:

>HiYa
>
>I looked at the doco on this and found that the number that is returned
>into the indicator variable is not the length, is there another way to
>get rid of the space at the end of the variables?
>
>perhaps I'll use some local varchar and strcpy this into the char[]'s
>
>thanks

You can use the EXEC SQL VAR <varname> TYPE STRING(x); directive for your host variables instead. Consider:

main( argc, argv )
int argc;
char * argv[];
{
VARCHAR oracleid[50];

VARCHAR     vcVariable[40];
char        charVariable[40];
char        asciizVariable[40];

exec sql var asciizVariable is STRING(40);

    strcpy( oracleid.arr, "tkyte/tkyte" );     oracleid.len = strlen( oracleid.arr );

    EXEC SQL WHENEVER SQLERROR DO sqlerror_hard();     EXEC SQL CONNECT :oracleid;
    printf("\nConnected to ORACLE as user: %s\n\n", oracleid.arr);

    exec sql declare c1 cursor for select ename, ename, ename from emp;     exec sql open c1;
    for(;;)
    {

        exec sql whenever not found do break;
        exec sql fetch c1 into :vcVariable, :charVariable, asciizVariable;

        printf( "Vc = '%.*s'\n", vcVariable.len, vcVariable.arr );
        printf( "Char = '%s'\n", charVariable );
        printf( "Asciiz = '%s'\n", asciizVariable );
        printf( "================\n" );

    }
    exec sql whenever not found continue;     exec sql close c1;

    /* Disconnect from ORACLE. */
    EXEC SQL COMMIT WORK RELEASE;
    exit(0);
}

Vc = 'SMITH'

Char = 'SMITH                                  '
Asciiz = 'SMITH'

Vc = 'ALLEN'
Char = 'ALLEN                                  '
Asciiz = 'ALLEN'

VARCHAR, we tell you the length in .len
CHAR, blank padded to max length.
ASCIIZ, C null terminated string.

-- 
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
[Quoted] Current article is "Part I of V, Autonomous Transactions" updated June 21'st
 
Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation
Received on Fri Dec 17 1999 - 14:26:28 CET

Original text of this message