OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

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

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

The Unified Distributed Database for the AI Era.

Follow Us
Products
OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
Resources
DocsBlogLive DemosTraining & Certification
Company
About OceanBaseTrust CenterLegalPartnerContact Us
Follow Us

© OceanBase 2026. All rights reserved

Cloud Service AgreementPrivacy PolicySecurity
Contact Us
Document Feedback
  1. Documentation Center
  2. Embedded SQL in C for OceanBase
  3. V1.1.7
iconEmbedded SQL in C for OceanBase
V 1.1.7Enterprise Edition

ANSI dynamic SQL statements

Last Updated:2023-06-29 11:12:55  Updated
share
What is on this page
SQL statements description
ALLOCATE DESCRIPTOR
DEALLOCATE DESCRIPTOR
DESCRIBE INPUT DESCRIPTOR
DESCRIBE OUTPUT DESCRIPTOR
GET DESCRIPTOR
SET DESCRIPTOR
OPEN USING DESCRIPTOR
FETCH INTO DESCRIPTOR
Example
Example 1
Example 2

folded

share

#docslug#/ecob/ecob/V1.1.6/ansi-dynamic-sql OceanBase Embedded SQL in C (ECOB) supports dynamic SQL statements that are compatible with American National Standards Institute (ANSI) standards. ECOB currently supports the following SQL statements: ALLOCATE DESCRIPTOR, DEALLOCATE DESCRIPTOR, DESCRIBE INPUT DESCRIPTOR, DESCRIBE OUTPUT DESCRIPTOR, GET DESCRIPTOR, SET DESCRIPTOR, OPEN USING DESCRIPTOR, and FETCH INTO DESCRIPTOR. When you are not sure about the number of input or output host variables of an SQL statement, you can use ANSI dynamic SQL statements.

SQL statements description

ALLOCATE DESCRIPTOR

You can execute the ALLOCATE DESCRIPTOR statement to allocate the SQL description area.

Syntax:

EXEC SQL ALLOCATE DESCRIPTOR {:desc_name | string} [ WITH MAX occurrences];

Screenshot 2020-10-14 23.18.04.png

The desc_name parameter specifies the host variable of the description area name.

The string parameter specifies the string constant of the description area.

The occurrences parameter specifies the maximum number of hosts that can be included in the description area. Default value: 100.

DEALLOCATE DESCRIPTOR

You can execute the DEALLOCATE DESCRIPTOR statement to release the SQL description area.

Syntax:

EXEC SQL DEALLOCATE DESCRIPTOR  {:desc_name | string} ;

Screenshot 2020-10-14 23.19.10.png

The desc_name parameter specifies the host variable of the description area name.

The string parameter specifies the string constant of the description area.

DESCRIBE INPUT DESCRIPTOR

You can execute the DESCRIBE INPUT DESCRIPTOR statement to bind variable information.

Syntax:

EXEC SQL DESCRIBE INPUT stat_id USING [SQL] DESCRIPTOR {:desc_name | string} ;

Screenshot 2020-10-14 23.20.50.png

DESCRIBE OUTPUT DESCRIPTOR

You can execute the DESCRIBE OUTPUT DESCRIPTOR statement to query the output column information.

Syntax:

EXEC SQL DESCRIBE [OUTPUT] stat_id USING [SQL] DESCRIPTOR  {:desc_name | string} ;

Screenshot 2020-10-14 23.21.45.png

GET DESCRIPTOR

You can execute the GET DESCRIPTOR statement to query the item information of the SQL description area.

Syntax:

EXEC SQL GET DESCRIPTOR {:desc_name | string}  {:host_variable = COUNT | VALUE occur_idx [, :host_variable=ITEMs];

Screenshot 2020-10-14 23.33.19.png

The COUNT parameter returns the total number of bound variables.

The VALUE occur_idx parameter specifies the positions of host variables in the SQL description area.

The ITEMs parameter includes the following elements:

  • TYPE: The code of a data type. The following table lists the data type codes of general internal data types.

    Internal data type Data type code
    VARCHAR2 1
    NUMBER 2
    DATE 12
    CHAR 96
    BINARY_FLOAT 100
    BINARY_DOUBLE 101
  • LENGTH: The data length of the column.

  • SCALE: The number of digits after the decimal point.

  • PRECISION: The total number of digits of a number.

  • NULLABLE: Specifies whether to allow values of a column to be NULL. At present, the value is fixed to 1.

  • DATA: Specifies to get data.

  • NAME: Specifies to get the column name.

  • INDICATOR: Specifies to get the value of the indicator variable.

SET DESCRIPTOR

You can execute the SET DESCRIPTOR statement to set the item information of the SQL description area.

Syntax:

EXEC SQL SET DESCRIPTOR {:desc_name | string}   {COUNT = :host_variable  | VALUE occur_idx [, ITEMs=:host_variable];

Screenshot 2020-10-14 23.31.28.png

The COUNT parameter specifies the total number of input variables or output variables. The VALUE occur_idx parameter specifies the positions of the host variables in the SQL description area.

The ITEMs parameter includes the following elements:

  • TYPE: The code of a data type.

  • LENGTH: The data length of the column.

  • DATA: Specifies to get data.

  • INDICATOR: Specifies to get the value of the indicator variable.

OPEN USING DESCRIPTOR

You can execute the OPEN USING DESCRIPTOR statement to open the cursor variable in the ANSI dynamic SQL statement.

Syntax:

EXEC SQL OPEN {cur_name} USING DESCRIPTOR {:desc_name | string} ;

Screenshot 2020-10-14 23.23.13.png

The cur_name parameter specifies the cursor name.

The desc_name parameter specifies the host variable of the description area name.

The string parameter specifies the string constant of the description area.

FETCH INTO DESCRIPTOR

You can execute the FETCH INTO DESCRIPTOR statement to obtain the result set stored by the cursor variable.

Syntax:

EXEC SQL FETCH {cur_name} INTO DESCRIPTOR {:desc_name | string};

Screenshot 2020-10-14 23.24.12.png

The cur_name parameter specifies the cursor name. The desc_name parameter specifies the host variable of the description area name. The string parameter specifies the string constant of the description area.

Example

Example 1

int type = 2;
int len = 4;
int val1 = 12;
int val2 = 0;
EXEC SQL ALLOCATE DESCRIPTOR in_desc;
EXEC SQL CREATE TABLE t1(c1 int, c2 int);
EXEC SQL INSERT INTO t1 VALUES(12, 24);
EXEC SQL PREPARE stmt1 FROM "select c2 from t1 where c1 = :val";
EXEC SQL DESCRIBE INPUT stmt1 USING SQL DESCRIPTOR in_desc;
EXEC SQL SET DESCRIPTOR in_desc VALUE 1 TYPE = :type;
EXEC SQL SET DESCRIPTOR in_desc VALUE 1 LENGTH = :len, DATA = :val1;
EXEC SQL DECLARE d_cursor CURSOR FOR stmt1;
EXEC SQL OPEN d_cursor USING DESCRIPTOR in_desc;
EXEC SQL FETCH d_cursor into :val2;
EXEC SQL DEALLOCATE DESCRIPTOR in_desc;
EXEC SQL DROP TABLE descriptor_1;

Example 2

int count;
int length;
int len1 = 100;
int len2 = 0;
int val = 0;
char * desc_name="out_desc";
EXEC SQL ALLOCATE DESCRIPTOR :desc_name;
EXEC SQL CREATE TABLE t1(c1 int, c2 int);
EXEC SQL PREPARE stmt1 FROM "select c1, c2 from t1";
EXEC SQL DESCRIBE OUTPUT stmt1 USING SQL DESCRIPTOR :desc_name;
EXEC SQL GET DESCRIPTOR :desc_name VALUE 2 :length = LENGTH;
EXEC SQL GET DESCRIPTOR :desc_name :count = COUNT;
EXEC SQL SET DESCRIPTOR :desc_name VALUE 1 LENGTH = :len1;
EXEC SQL GET DESCRIPTOR :desc_name VALUE 1 :len2 = LENGTH;
EXEC SQL INSERT INTO t1 VALUES(1, 2);
EXEC SQL DECLARE d_cursor CURSOR FOR stmt1;
EXEC SQL OPEN d_cursor;
EXEC SQL FETCH d_cursor into DESCRIPTOR :desc_name;
EXEC SQL GET DESCRIPTOR :desc_name VALUE 1 :val = DATA;
EXEC SQL DEALLOCATE DESCRIPTOR :desc_name;
EXEC SQL DROP TABLE t1;

Previous topic

Simple dynamic SQL statement
Last

Next topic

SQLCA structure
Next
What is on this page
SQL statements description
ALLOCATE DESCRIPTOR
DEALLOCATE DESCRIPTOR
DESCRIBE INPUT DESCRIPTOR
DESCRIBE OUTPUT DESCRIPTOR
GET DESCRIPTOR
SET DESCRIPTOR
OPEN USING DESCRIPTOR
FETCH INTO DESCRIPTOR
Example
Example 1
Example 2