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

Home -> Community -> Usenet -> c.d.o.misc -> Re: VARCHAR2 in Pro*C

Re: VARCHAR2 in Pro*C

From: Lance Humpert <Lance.Humpert_at_mail.tju.edu>
Date: 1997/04/23
Message-ID: <01bc5020$3be76fd0$f0828c93@lhumpert>#1/1

Thomas Booker <booket01_at_mchip00.med.nyu.edu> wrote:

> When I select the column in Pro*C, it pads the column out to
> 550 spaces, regardless of how long the actual string is.
>
> Is there an easy way around this?

It sounds to me as if you are declaring the host variables in your sql area as 'char' datatypes instead of using Oracle's 'varchar' datatype.

The 'char' datatype will always be blank-padded by Oracle, whereas the 'varchar' datatype will be varying length. The catch is, however, that varchars are not null terminated. Instead, oracle provides a length byte as part of the varchar data structure so that you know the length of the field that was fetched.

You see, varchars get expanded by the pro*c precompiler into little structs that contain a length byte and a charater array. These components are can be referenced in your pro*c source code by adding a suffix of either '.len' for the length byte or '.arr' for the character array to your field name.

If you are already using varchars in your sql area, then I have no idea what I'm talking about! If not, and if you convert to varchars and still have problems, welcome to the club.

FYI, I don't use the length byte, opting instead to fill each character array with null values prior to fetching from oracle. That way, my varchars are null terminated (as long as they're one byte longer that the longest value fetched).

Good luck,
Lance Humpert
Client Server Programmer/Analyst
Thomas Jefferson University
Philadelphia, Pa. Received on Wed Apr 23 1997 - 00:00:00 CDT

Original text of this message

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