Re: Char vs Varchar2 and NULL

From: Programming <sysdev_at_mb.sympatico.ca>
Date: 1998/09/08
Message-ID: <35F58BC8.5076_at_mb.sympatico.ca>#1/1


HI,

VARCHAR is actually a STRUCTURE/RECORD.

It has two components,

	array 	(.arr) and
	length	(.len)

You have to be careful when using these variables to set the length.

So, typically, in embedded SQL programs in C.

	SELECT ...
	INTO :varchar_variable	
	...

  • the length (.len) will automatically be set by this retrieve.
  • then you must null terminate in the correct place:

varchar_variable.arr[varchar_variable.len] = '\0';

However, a char variable is just an array of char.

I hope that this might be of some help.

Rodger

> Declare
> V Varchar2(3);
> C Char(3);
> Begin
> V := Null;
> C := V;
> DBMS_Output.Put_Line
> ('Char = |' || C || '| (Set from NULL varchar2');
> V := '';
> C := V;
> DBMS_Output.Put_Line
> ('Char = |' || C || '| (Set from zero-length varchar2');
> End;
> /
>
> The output looks like this:
> Char = || (Set from NULL varchar2
> Char = | | (Set from zero-length varchar2
> The second value is three spaces!
>
> Apparently, there is a difference between NULL and Zero-Length
> values in Varchar2 fields.
Received on Tue Sep 08 1998 - 00:00:00 CEST

Original text of this message