Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Problem with Pro*C

Re: Problem with Pro*C

From: Jacques Raymond Kilchoer <jrkilch_at_costcare.com>
Date: 1997/06/12
Message-ID: <33A01E4D.3D5B@costcare.com>#1/1

Balaji.S wrote:
> I am a newbie to Pro*C.
> I am having problems with Pro*C. I am using varchar variables in a loop
> and fetching records into those variables from a cursor. I am writing
> these variables to a text file for archival purposes. In-spite of NULL
> terminating these varchar variables, I find that in subsequent retrievals
> the old value contained in the varchar variable mix up with the newly
> fetched ones. variablename.arr will have both the old and the new values
> mixed up. Is there something very important i am missing.

I'm not sure if this answers your question?! When you select into a varchar field, ORACLE only overwrites the array up to varchar.len bytes, all the other bytes are left untouched. (see example below)

SQL> describe customer

 Name                            Null?    Type
 ------------------------------- -------- ----
 CUSTOMER_ID                     NOT NULL NUMBER(38)
 LAST_NAME                       NOT NULL VARCHAR2(10)

ProC

varchar last_name[10 + 1] ;
/* ... */
/* fill the field with blanks */
memset (last_name.arr, ' ', sizeof last_name.arr) ;

exec sql

   select last_name into :last_name
   from customer
   where customer_id = 1 ;

/* null-terminate the string */
last_name.arr[last_name.len] = '\0' ;

/* assume last_name is 'SMITH' for customer_id 1 */
/* last_name.arr contains:
 * 'S', 'M', 'I', 'T', 'H', '\0 ', ' ', ' ', ' ', ' '
 */

exec sql

   select last_name into :last_name
   from customer
   where customer_id = 2 ;

/* null-terminate the string */
last_name.arr[last_name.len] = '\0' ;

/* assume last_name is 'LI' for customer_id 2 */
/* last_name.arr contains:
 * 'L', 'I', '\0', 'T', 'H', '\0 ', ' ', ' ', ' ', ' '
 */

-- 
 ___                                                               ___
(___)=============================================================(___)
|   | Jacques Raymond Kilchoer           MIS:Applications Support |   |
|   | Assistant DBA               /^\  ^     (714) 729-4500 x3733 |   |
|   | Cost Care, Inc.       /\  _/   \/ \            fax 729-4651 |   |
|   | Newport Beach   /\ /\/  \//     \  \_/\                     |   |
|   | CA 92660       /  \ /    /       \ /   \   Suisse/Schweizer |   |
|___|           ____/____\____/_________\___ _\_______   Svizzero |___|
(___)=============================================================(___)
Received on Thu Jun 12 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US