Re: Char & Varchar2
Date: 1998/02/24
Message-ID: <34F2E8E7.207E0C5E_at_fairway_NO_SPAM_.com>#1/1
Thomas Ruschak wrote:
>
> Hey, can anyone give me a quick couple of lines overview on when
> to use char & when varchar2? What are the overhead costs associated with
> varchar2?
The VARCHAR datatype is acutally implemented as a structure in C. The data structure has the following form: (note: that the arr field is of type 'unsigned char' -- Nobody at Oracle can give you a good reason for this)
(gdb) p m_cancel
$1 = {
len = 1,
arr = "Y\000"
}
(gdb)
Where m_cancel.len carries the length (in bytes) of the string read from the database and the m_cancel.arr carries the actual value of the string. In this case, the VARCHAR variable m_cancel is a 1 byte string with the value of 'Y'.
For the VARCHAR string, to copy data into the string:
strcpy(string.arr, "string to copy");
To assign the length of the string:
string.len = strlen(string);
To NULL terminate the string:
string.len+1 = '\0';
The VARCHAR datatype is quite useful because it has the length assigned on output from the database. This means you don't have to use a call to strlen and you can do useful stuff like this:
[Quoted] VARCHAR oracle_string[80]; char new_string[20]; strncpy(new_string, oracle_string, oracle_string.len);
Thus, you know the sizeof the oracle_string from its len field.
Jeff
-- Senior Software Engineer Fairway Systems, Inc. /* remove the _NO_SPAM_ to reply */Received on Tue Feb 24 1998 - 00:00:00 CET