#docslug#/ecob/ecob/V1.1.6/varchar-variable The VARCHAR variable is a character string with a variable length. It is defined using the VARCHAR type.
The VARCHAR type can be used to define host variables only. When you define a VARCHAR variable, specify the length of the variable. Sample statement:
VARCHAR name[20];
The VARCHAR variable will be precompiled to generate the following C structure:
struct{
unsigned short len;
unsigned char arr[20];
}name;
The arr member of the structure corresponds to the character string, and the len member indicates the actual length of the character string. You can directly reference these two members in an application. Sample statement:
varchar name[20];
strcpy(name.arr,"test");
name.len = strlen(name.arr);
EXEC SQL create table t1 (c1 varchar2(100));
EXEC SQL insert into t1 values(:name);
EXEC SQL COMMIT WORK;
When the VARCHAR variable is used as an output host variable, the arr and len members of the structure are automatically copied. Sample statement:
varchar name[20];
EXEC SQL create table t1 (c1 varchar2(100),c2 int);
EXEC SQL insert into t1 values('abc',1);
EXEC SQL select c1 into :name from t1 where c2=1;
name.arr[name.len]='\0';