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

Basic SQL statements

Last Updated:2023-06-29 11:12:55  Updated
share
What is on this page
COMMIT
ROLLBACK
SELECT
SELECT INTO
INSERT
UPDATE
DELETE
SAVEPOINT statement

folded

share

OceanBase Embedded SQL in C (ECOB) supports the following basic SQL statements: SELECT, INSERT, UPDATE, DELETE, COMMIT, ROLLBACK, and SAVEPOINT.

COMMIT

You can execute the COMMIT statement to commit a transaction. You can specify whether to release resources and disconnect a database connection.

Syntax:

EXEC SQL COMMIT [WORK] [COMMENT 'text'] [RELEASE]

Screenshot 2020-10-14 21.58.19.png

The COMMIT WORK parameter and the COMMIT parameter are equivalent. The RELEASE parameter is used to release all resources and disconnect the current database connection.

Sample statements:

EXEC SQL COMMIT WORK;
EXEC SQL COMMIT WORK RELEASE;
EXEC SQL COMMIT RELEASE;

ROLLBACK

You can execute the ROLLBACK statement to roll back a transaction. You can specify whether to release resources and disconnect a database connection.

Syntax:

EXEC SQL ROLLBACK [WORK] [RELEASE]

Screenshot 2020-10-14 21.58.35.png

The RELEASE parameter is used to release all resources and disconnect the current database connection.

Sample statements:

EXEC SQL ROLLBACK WORK;
EXEC SQL ROLLBACK WORK RELEASE;

SELECT

You can execute the SELECT statement to execute the query statement and assign the query result to external host variables.

Syntax:

EXEC SQL SELECT <select_list> INTO : (host_variable) [ [INDICATOR] : (indicator_variable) ] FROM (table_list) [WHERE (condition)]

Screenshot 2020-10-14 22.26.02.png

The SELECT statement follows the syntax of the SELECT statement in OceanBase Oracle mode. The host variable after the SELECT...INTO clause is used to import data read from databases to an application. The query result of the SELECT statement must be one row. Otherwise, an error is reported.

Sample statements:

short ind;
int c1val;
EXEC SQL CREATE TABLE T1 (c1 int,c2 int);
EXEC SQL INSERT t1 values (1,2);
EXEC SQL SELECT c1 INTO :c1val:ind FROM t1 WHERE c2=2;

SELECT INTO

ECOB supports the storage of SQL results in two-dimensional arrays by using the SELECT INTO statement.

Sample statements:

EXEC SQL  create table t1(id number not null primary key , name varchar2(50) not null, unique (name)) partition by hash(id) partitions 8;
// An arr_id one-dimensional array.
int arr_id[2];
EXEC SQL  select id into :arr_id from t1 where id>1 and id<4 order by id;
printf("Character strings can be stored in an arr_name two-dimensional array. The row indicates the number of strings, and the column indicates the length \n");
// An arr_mix two-dimensional array.
char arr_mix[2][4];
EXEC SQL  select id into :arr_mix from t1 where id=1;

INSERT

You can execute INSERT statement to execute an insert statement. This statement allows you to write external host variables into table columns of databases.

Syntax:

EXEC SQL INSERT INTO <table_name> ( col_list ) VALUES ( expr | :host_variable )

Screenshot 2020-10-14 22.32.44.png

The INSERT statement follows the syntax of the INSERT statement in OceanBase Oracle mode.

Sample statements:

int c1val = 0;
char * c2val = "demo";
EXEC SQL CREATE TABLE t1 (c1 int,c2 varchar2(100));
EXEC SQL INSERT INTO t1 VALUES (:c1val,:c2val);
EXEC SQL INSERT INTO t1(c1) VALUES (:c1val);
EXEC SQL COMMIT WORK;
EXEC SQL DROP TABLE t1;

UPDATE

You can execute the UPDATE statement to execute an update statement. You can specify whether to synchronize values of external variables to table columns of databases or update the column where the cursor is located.

Syntax:

EXEC SQL UPDATE <table_name> SET <column = expr>  [WHERE (condition | CURRENT OF <cursor>)]

Screenshot 2020-10-14 22.37.25.png

The UPDATE statement follows the syntax of the UPDATE statement in OceanBase Oracle mode. In this statement, CURRENT OF <cursor> specifies the current column pointed by the cursor, and cursor specifies the name of the cursor. When you define a cursor, you must explicitly add the FOR UPDATE statement to the SELECT statement.

Sample statements:

int c1val = 10;
int c1ret;
char * c2val = "update demo";
EXEC SQL CREATE TABLE t1 (c1 int,c2 varchar2(100));
EXEC SQL INSERT INTO t1 VALUES (1,'init val');
EXEC SQL UPDATE t1 SET c2=:c2val WHERE c1 < :c1val;
EXEC SQL INSERT INTO t1 VALUES (10,'more val');
EXEC SQL INSERT INTO t1 VALUES (20,'more val');
EXEC SQL INSERT INTO t1 VALUES (30,'more val');
EXEC SQL COMMIT WORK;
EXEC SQL DECLARE cur SCROLL CURSOR for select c1 from t1 for update;
EXEC SQL OPEN cur;
EXEC SQL FETCH ABSOLUTE 2 cur INTO :c1ret ;
EXEC SQL UPDATE t1 set c2=:c2val where CURRENT OF cur;
EXEC SQL CLOSE cur;
EXEC SQL COMMIT WORK;

DELETE

You can execute the DELETE statement to execute a delete statement. This statement allows you to delete one or more rows of data in databases or delete the column where the cursor is located.

Syntax:

EXEC SQL DELETE FROM <table_name> [WHERE (condition | CURRENT OF <cursor>) ]

Screenshot 2020-10-14 23.00.08.png

The DELETE statement follows the syntax of the DELETE statement in OceanBase Oracle mode. In this statement, CURRENT OF <cursor> specifies the current column pointed by the cursor, and cursor specifies the name of the cursor. When you define a cursor, you must explicitly add the FOR UPDATE statement to the SELECT statement.

Sample statements:

int c1val = 10;
int pos=2;
int c1ret;
char * c2val = "update demo";
char * username="**u***";
char * password="**1***";
char * servicename="**s***";
EXEC SQL CONNECT :username identified by :password using :servicename;
EXEC SQL DROP TABLE T1;
EXEC SQL CREATE TABLE t1 (c1 int,c2 varchar2(100));
EXEC SQL INSERT INTO t1 VALUES (1,'init val');
EXEC SQL UPDATE t1 SET c2=:c2val WHERE c1 < :c1val;
EXEC SQL INSERT INTO t1 VALUES (10,'more val');
EXEC SQL INSERT INTO t1 VALUES (20,'more val');
EXEC SQL INSERT INTO t1 VALUES (30,'more val');
EXEC SQL COMMIT WORK;
EXEC SQL DECLARE cur SCROLL CURSOR for select c1 from t1 for update;
EXEC SQL OPEN cur;
EXEC SQL FETCH ABSOLUTE 3 cur INTO :c1ret ;
EXEC SQL delete from t1 where CURRENT OF cur;
EXEC SQL CLOSE cur;
EXEC SQL COMMIT WORK;

SAVEPOINT statement

The SAVEPOINT statement is used to set a transaction savepoint. If a savepoint with the same name already exists in the current transaction, the old savepoint is deleted and a new savepoint is set. After a transaction ends, all savepoints are automatically released.

Syntax:

EXEC SQL SAVEPOINT pointname;

Logic diagram

Sample statement:

EXEC SQL SAVEPOINT saveX;
exec sql rollback to savepoint savex;

Previous topic

Connect to OceanBase databases
Last

Next topic

Prepared statements
Next
What is on this page
COMMIT
ROLLBACK
SELECT
SELECT INTO
INSERT
UPDATE
DELETE
SAVEPOINT statement