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: PROC Ver 2.2 - VARCHAR contents not properly overwritten

Re: PROC Ver 2.2 - VARCHAR contents not properly overwritten

From: Jacques Raymond Kilchoer <jrkilch_at_costcare.com>
Date: 1997/06/11
Message-ID: <339EEF85.4DA5@costcare.com>#1/1

Corin Lanser wrote:
>
> Hi,
>
> My problem is that when I have an array of the standard VARCHAR strings.
> If I get Oracle to put data into the array more than once, the previous
> data is only overwritten UPTO the length of the new data string.
>

I have PROC 2.0 on VAX VMS, but I'm sure the behaviour is the same in your version.
If I declare a varchar field, the compiler actually creates a structure with two members: arr (which is the character array) and len (which is the length of the string). Use len to know how many characters were retrieved from the database.

Example:
SQL> describe customer;

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


Here are the two ways I've handled varchar fields in the past:

a)
varchar last_name[20 + 1] ; /* add 1 byte for null termination */

select last_name into :last_name from customer where customer_id = 1 ;
last_name.arr[last_name.len] = '\0' ; /* terminate string after select */
/* Now I can use last_name.arr as a null-terminated C string */ printf ("Last name is %s\n", last_name.arr) ;

b)
varchar last_name[20] ;

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

/* now use strn functions for last name */ if (strncmp (last_name.arr, "SMITH", last_name.len) == 0) /* to check of last name is SMITH */ ;
printf ("Last name is %.*s\n", (int) last_name.len, last_name.arr) ; /* to print the last name */

etc...

-- 
 ___                                                               ___
(___)=============================================================(___)
|   | 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 Wed Jun 11 1997 - 00:00:00 CDT

Original text of this message

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