Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002
    Location
    Shanghai , China
    Posts
    63

    Unanswered: right padding space on Varchar2 (PRO*C)

    I am using Pro*C for Oracle8.1.7

    I have a doubt on Varchar2 column :
    Describing emp....
    NAME Null? Type
    ------------------------------- --------- -----
    EMPNO NOT NULL NUMBER(4,0)
    ENAME VARCHAR2(10)

    But the ENAME stores only 5 chars

    In .PC file

    typedef char asciiz[11];

    EXEC SQL TYPE asciiz IS CHARZ(11) REFERENCE;

    struct emp_info
    {
    asciie emp_name;
    float salary;
    float commission;
    };
    ...
    EXEC SQL DECLARE salespeople CURSOR FOR
    SELECT RTRIM(ENAME), SAL, COMM
    FROM EMP
    WHERE JOB LIKE 'SALES%';
    .......

    for (;
    {
    EXEC SQL FETCH salespeople INTO :emp_rec_ptr;
    printf("%s %9.2f %12.2f\n", emp_rec_ptr->emp_name,
    emp_rec_ptr->salary, emp_rec_ptr->commission);
    printf("length (name) = %d \n",strlen(emp_rec_ptr->emp_name));
    }

    It shows the length of emp_name is 10 ( right padded space )

    Why it happens like that ?


    __________________
    Oracle is an ocean . I am just a little fish

  2. #2
    Join Date
    Jan 2003
    Location
    Woking
    Posts
    107

    Re: right padding space on Varchar2 (PRO*C)

    Originally posted by ligang
    I am using Pro*C for Oracle8.1.7

    I have a doubt on Varchar2 column :
    Describing emp....
    NAME Null? Type
    ------------------------------- --------- -----
    EMPNO NOT NULL NUMBER(4,0)
    ENAME VARCHAR2(10)

    But the ENAME stores only 5 chars

    In .PC file

    typedef char asciiz[11];

    EXEC SQL TYPE asciiz IS CHARZ(11) REFERENCE;

    struct emp_info
    {
    asciie emp_name;
    float salary;
    float commission;
    };
    ...
    EXEC SQL DECLARE salespeople CURSOR FOR
    SELECT RTRIM(ENAME), SAL, COMM
    FROM EMP
    WHERE JOB LIKE 'SALES%';
    .......

    for (;
    {
    EXEC SQL FETCH salespeople INTO :emp_rec_ptr;
    printf("%s %9.2f %12.2f\n", emp_rec_ptr->emp_name,
    emp_rec_ptr->salary, emp_rec_ptr->commission);
    printf("length (name) = %d \n",strlen(emp_rec_ptr->emp_name));
    }

    It shows the length of emp_name is 10 ( right padded space )

    Why it happens like that ?


    __________________
    Hi,
    Try using the varchar datatype. varchar datatype is a "c" structure and
    padding of spaces is not a problem here.

    Usage would be

    VARCHAR HV_emp_name[50];

    HV_emp_name.arr will have the Data which has to be null terminated at
    HV_emp_name.len(this member variable will contain the actual length
    of the data string)

    Hope it Helps.
    nn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •