OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog ServiceOceanBase DataPilot

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog ServiceOceanBase DataPilot
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

Embedded SQL in C for OceanBase

V1.1.7Enterprise Edition
  • What's New
  • What is ECOB?
  • ECOB compatibility with Pro*C
  • Install ECOB
  • Data types and variables
    • Overview
    • Supported data types
    • Data type conversion
    • Indicator variable
    • VARCHAR variable
    • Structure
    • String pointer
  • Embedded SQL statements
    • Overview
    • Variable declaration
    • Connect to OceanBase databases
    • Basic SQL statements
    • Prepared statements
    • Stored procedures
    • Cursor
    • Simple dynamic SQL statement
    • ANSI dynamic SQL statements
    • Error handling
      • SQLCA structure
      • WHENEVER statement
    • LOB-related SQL statements
  • Use ECOB
    • Environment preparation
    • Use ECOB
    • Compile the Tuxedo service
  • Command Line Options

Download PDF

Document Feedback
  1. Documentation Center
  2. Embedded SQL in C for OceanBase
  3. V1.1.7

VARCHAR variable

Last Updated:2026-09-04 08:37:38

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';

Previous topic

Indicator variable
Last

Next topic

Structure
Next