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

Basic SQL statements

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

COMMIT
ROLLBACK
SELECT
SELECT INTO
INSERT
UPDATE
DELETE
SAVEPOINT statement

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
on this page
COMMIT
ROLLBACK
SELECT
SELECT INTO
INSERT
UPDATE
DELETE
SAVEPOINT statement