OceanBase logo

OceanBase

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

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

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

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

OceanBase Database

SQL - V4.0.0

  • Document overview
  • Overview
    • Overview
    • System architecture
    • Compatibility with MySQL
    • Limits
  • Get Started
    • Quick experience
    • Hands on for OceanBase SQL
      • Before you start
      • Basic SQL operations
    • Create a sample application
      • Connect to OceanBase Database by using a Python driver
      • Connect to OceanBase Database by using Go MySQL Driver
      • Connect a Java application to OceanBase Database
      • Connect a C application to OceanBase Database
    • Experience OceanBase advanced features
      • Experience scalable OLTP
        • Run the TPC-C benchmark test on OceanBase Database
        • Experience the hot row update capability of OceanBase Database
      • Experience operational OLAP
      • Experience parallel import and data compression
      • Experience the multitenancy feature
  • Develop
    • Connect to Oceanbase Database with client
      • Overview
      • Connect to OceanBase Database by using a MySQL client
      • Connect to OceanBase Database by using OBClient
      • Connect to OceanBase Database by using ODC
      • Connect Java applications to OceanBase Database
      • Connect to OceanBase Database by using Go MySQL Driver
      • Connect to OceanBase Database by using Unix ODBC
      • C application
        • OceanBase Connector/C
        • C API functions
        • Connect C applications to OceanBase Database
      • Connect Python applications to OceanBase Database
      • SpringBoot connection example
      • SpringBatch connection example
      • SpringJDBC connection example
      • SpringJPA connection example
      • Hibernate connection example
      • MyBatis connection example
      • Example of Database connection pool configuration
        • Overview of database connection pool configuration
        • Example of configuring a Tomcat connection pool
        • Example of configuring a C3P0 connection pool
        • Example of configuring a Proxool connection pool
        • Example of configuring a HiKariCP connection pool
        • Example of configuring a DBCP connection pool
        • CommonPool configuration example
        • Example of configuring a JDBC connection pool
    • Create and manage database objects
      • About DDL statements
      • View the currently connected database
      • Change the password of a user
      • Data type
        • General data types
        • Unsupported data types
      • Create and manage tables
        • About tables
        • Create a table
        • About auto-increment columns
        • About types of column constraints
        • About table structure modification
        • About table clearing
        • About table dropping
        • Flash back a dropped table
        • About table privileges
      • Create and manage partition tables
        • About partitioned tables
        • Create a partitioned table
        • Manage a partitioned table
        • Create a subpartitioned table
        • Manage a subpartitioned table
        • Partition routing
        • Indexes on partitioned tables
        • Suggestions on using partitioned tables
      • Create and manage indexes
        • About indexes
        • Create an index
        • Drop an index
      • Create and manage views
        • About views
        • Create a view
        • Modify a view
        • Delete a view
      • Create and manage sequences
        • About sequences
        • Create a sequence
        • Modify a sequence
        • Delete a sequence
    • Query
      • About queries
      • Single-table queries
      • Conditional queries
      • ORDER BY queries
      • GROUP BY queries
      • Use the LIMIT clause in queries
      • Query data from multiple tables
        • About multi-table join queries
        • INNER JOIN queries
        • OUTER JOIN queries
        • Subqueries
      • Use operators and functions in a query
        • Use arithmetic operators in queries
        • Use numerical functions in queries
        • Use string connectors in queries
        • Use string functions in queries
        • Use datetime functions in queries
        • Use type conversion functions in queries
        • Use aggregate functions in queries
        • Use NULL-related functions in queries
        • Use the CASE conditional operator in queries
        • Use the SELECT FOR UPDATE statement to lock query results
      • Execution plan
        • View an execution plan
        • Understand an execution plan
      • Use SQL hints in queries
      • Variables of query timeout
    • DML statements and transactions
      • DML statement
        • About DML statements
        • About the INSERT statement
        • UPDATE statements
        • About the DELETE statement
        • About the REPLACE INTO statement
      • Transactions
        • About transaction control statements
        • Start a transaction
        • Transaction savepoints
        • Commit a transaction
        • Roll back a transaction
        • About transaction timeout
    • Common errors and solutions
      • About error codes
      • Database connection error
      • About timeout
        • Idle session timeout
        • Transaction timeout errors
      • About user
        • Locked user
        • Incorrect user password
      • About table
        • Table already exists
        • Table does not exist
        • Invalid use of NULL value
      • About constraint
        • Unique key conflict
        • Foreign key conflict
      • About SQL commands
        • Data truncation
  • Deploy
    • Overview
    • On-premises deployment
      • Software and hardware requirements
      • Configuration before deployment
      • Deploy OceanBase Database online
      • Deploy OceanBase Database offline
    • Deploy OceanBase Database in a Kubernetes cluster
    • High availability deployment
      • Use Alibaba Otter to implement remote active-active disaster recovery
  • Migrate
    • Data Migration Overview
    • Migrate data from MySQL Database to OceanBase
      • Use Canal to synchronize MySQL data to OceanBase Database in real time
      • Use DataX to migrate MySQL data to OceanBase Database
      • Use DBCAT to migrate MySQL table schemas to OceanBase Database
      • Migrate MySQL table schemas to OceanBase Database by using mysqldump
      • Migrate MySQL table data to OceanBase Database by using mysqldump
    • Use OBDUMPER to export data from or OBLOADER to import data to OceanBase Database
    • Migrate data from CSV-file to OceanBase
      • Use DataX to load CSV data files to OceanBase Database
      • Use the LOAD DATA statement to load CSV data files to OceanBase Database
    • Migrate data from SQL files to OceanBase Database
    • Migrate data and resource units between tables
    • Migrate data from OceanBase Database to MySQL
      • Use Canal to synchronize OceanBase Database data to MySQL in real time

Download PDF

Document overview Overview System architecture Compatibility with MySQL Limits Quick experience Before you start Basic SQL operations Connect to OceanBase Database by using a Python driver Connect to OceanBase Database by using Go MySQL Driver Connect a Java application to OceanBase Database Connect a C application to OceanBase Database Experience operational OLAP Experience parallel import and data compression Experience the multitenancy feature Overview Connect to OceanBase Database by using a MySQL client Connect to OceanBase Database by using OBClient Connect to OceanBase Database by using ODC Connect Java applications to OceanBase Database Connect to OceanBase Database by using Go MySQL Driver Connect to OceanBase Database by using Unix ODBC Connect Python applications to OceanBase Database SpringBoot connection example SpringBatch connection example SpringJDBC connection example SpringJPA connection example Hibernate connection example MyBatis connection example About DDL statements View the currently connected database Change the password of a user About queries Single-table queries Conditional queries ORDER BY queries GROUP BY queries Use the LIMIT clause in queries Use SQL hints in queries Variables of query timeout About error codes Database connection error Overview Software and hardware requirements Configuration before deployment Deploy OceanBase Database online Deploy OceanBase Database offline Deploy OceanBase Database in a Kubernetes cluster Use Alibaba Otter to implement remote active-active disaster recovery Data Migration Overview Use Canal to synchronize MySQL data to OceanBase Database in real time Use DataX to migrate MySQL data to OceanBase Database Use DBCAT to migrate MySQL table schemas to OceanBase Database Migrate MySQL table schemas to OceanBase Database by using mysqldump Migrate MySQL table data to OceanBase Database by using mysqldump Use OBDUMPER to export data from or OBLOADER to import data to OceanBase Database Use DataX to load CSV data files to OceanBase Database Use the LOAD DATA statement to load CSV data files to OceanBase Database Migrate data from SQL files to OceanBase Database Migrate data and resource units between tables Use Canal to synchronize OceanBase Database data to MySQL in real time
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. OceanBase Database
  3. SQL
  4. V4.0.0
iconOceanBase Database
SQL - V 4.0.0
SQL
KV
  • V 4.4.2
  • V 4.3.5
  • V 4.3.3
  • V 4.3.1
  • V 4.3.0
  • V 4.2.5
  • V 4.2.2
  • V 4.2.1
  • V 4.2.0
  • V 4.1.0
  • V 4.0.0
  • V 3.1.4 and earlier

C API functions

Last Updated:2023-07-21 09:11:01  Updated
share
What is on this page
Overview
Example

folded

share

This topic describes the general C API functions.

Overview

The following table lists all C API functions available to OceanBase Connector/C.

For more information about the APIs, see C API functions in the OceanBase Connector/C.

Name Description
my_init() Initializes global variables in OceanBase Database.
mysql_affected_rows() Returns the number of rows modified, deleted, or inserted by the last UPDATE, DELETE, or INSERT statement.
mysql_autocommit() Sets the autocommit mode.
mysql_change_user() Modifies the user and database on an open connection.
mysql_character_set_name() Returns the name of the default character set for the current connection.
mysql_client_find_plugin() Returns a pointer to a plug-in.
mysql_client_register_plugin() Registers a plug-in.
mysql_close() Closes the connection with the server.
mysql_commit() Commits a transaction.
mysql_connect() Connects to the server. This function is deprecated.
mysql_create_db() Creates a database. This function is deprecated.
mysql_data_seek() Searches for an arbitrary row in a result set.
mysql_debug() Uses a given string to perform a DBUG_PUSH operation.
mysql_drop_db() Drops a database. This function is deprecated.
mysql_dump_debug_info() Instructs the server to write debugging information to the error log.
mysql_eof() Checks whether the last row in a result set is already read. This function is deprecated.
mysql_errno() Returns the error code generated for the last called API function.
mysql_error() Returns the error message generated for the last called API function.
mysql_escape_string() Escapes special characters in a string so that it can be used in an SQL statement.
mysql_fetch_field() Returns the next field.
mysql_fetch_field_direct() Returns the field with the specified field number.
mysql_fetch_fields() Returns an array of all field structures.
mysql_fetch_lengths() Returns the lengths of the columns of the current row in a result set.
mysql_fetch_row() Retrieves the next row of a result set.
mysql_field_count() Returns the number of columns for the most recent query.
mysql_field_seek() Searches for columns of a row in a result set.
mysql_field_tell() Returns the position of the field used for the last call to the mysql_fetch_field() function.
mysql_free_result() Frees the memory allocated to a result set.
mysql_get_character_set_info() Returns the information about the default character set.
mysql_get_client_info() Returns a string that represents the OceanBase client library version.
mysql_get_client_version() Returns an integer that represents the OceanBase client library version.
mysql_get_host_info() Returns the connection information, including the server hostname.
mysql_get_proto_info() Returns the protocol version used for the current connection.
mysql_get_server_info() Returns a string that represents the server version.
mysql_get_server_version() Returns an integer that represents the server version.
mysql_get_ssl_cipher() Returns the current SSL password.
mysql_hex_string() Creates a hexadecimal string.
mysql_info() Returns the information about the most recently executed statement.
mysql_init() Obtains or initializes a connection structure.
mysql_insert_id() Returns the ID generated by the previous statement for an AUTO_INCREMENT column.
mysql_kill() Kills a thread. This function is deprecated.
mysql_library_end() Finalizes the C API library.
mysql_library_init() Initializes the C API library.
mysql_list_dbs() Returns database names that match a regular expression.
mysql_list_fields() Returns field names that match a regular expression.
mysql_list_processes() Returns the thread list of the server.
mysql_list_tables() Returns table names that match a regular expression.
mysql_load_plugin() Loads a plug-in.
mysql_load_plugin_v() Loads a plug-in.
mysql_more_results() Checks whether more results exist.
mysql_next_result() Returns the next statement result.
mysql_num_fields() Returns the number of columns in a result set.
mysql_num_rows() Returns the number of rows in a result set.
mysql_options() Sets connection options.
mysql_options4() Sets connection options.
mysql_ping() Checks whether the connection to the server is working.
mysql_plugin_options() Sets plug-in options.
mysql_query() Executes an SQL statement.
mysql_real_connect() Connects to the server.
mysql_real_escape_string() Encodes special characters in a string of a statement.
mysql_real_query() Execute the statement.
mysql_refresh() Flushes or resets tables or caches.
mysql_reload() Reloads the grant tables. This function is deprecated.
mysql_rollback() Rolls back a transaction.
mysql_row_seek() Searches for an arbitrary row in a query result set.
mysql_row_tell() Returns the current position of the row cursor for a result set.
mysql_select_db() Selects a database.
mysql_server_end() Finalizes the C API library.
mysql_server_init() Initializes the C API library.
mysql_set_character_set() Sets the default character set for the current connection.
mysql_set_local_infile_default() Sets the LOAD DATA LOCAL callback functions to the default values.
mysql_set_local_infile_handler() Installs callbacks to be used during the execution of LOAD DATA LOCAL statements.
mysql_set_server_option() Enables or disables an option for the current connection.
mysql_shutdown() Shuts down the server.
mysql_sqlstate() Returns the SQLSTATE value of the most recently called function.
mysql_ssl_set() Establishes an SSL connection to the server.
mysql_stat() Returns the status of the server.
mysql_stmt_affected_rows() Returns the number of rows modified, deleted, or inserted by the last UPDATE, DELETE, or INSERT statement.
mysql_stmt_attr_get() Obtains an attribute value of a prepared statement.
mysql_stmt_attr_set() Sets an attribute value for a prepared statement.
mysql_stmt_bind_param() Associates the input data with the parameter markers of a prepared statement.
mysql_stmt_bind_result() Associates data buffers with output columns in the result set.
mysql_stmt_close() Closes a prepared statement.
mysql_stmt_data_seek() Searches for an arbitrary row in the result set of a prepared statement.
mysql_stmt_errno() Returns the error code for the most recently called statement.
mysql_stmt_error() Returns the error message generated for the last called statement API function.
mysql_stmt_execute() Executes a prepared statement.
mysql_stmt_fetch() Returns the next row in a result set and returns the values of all associated columns.
mysql_stmt_fetch_column() Fetches one column from the current result set row.
mysql_stmt_field_count() Returns the number of columns in the result set of the most recently executed prepared statement.
mysql_stmt_free_result() Free resources allocated to the statement handler.
mysql_stmt_init() Allocates and initializes memory to the STMT structure.
mysql_stmt_insert_id() Returns the ID generated by the previous prepared statement for an AUTO_INCREMENT column.
mysql_stmt_next_result() Returns the next result in the result set of a prepared statement.
mysql_stmt_num_rows() Returns the number of rows in the result set of a statement.
mysql_stmt_param_count() Returns the number of parameters in a prepared statement.
mysql_stmt_param_metadata() Returns parameter metadata as a result set.
mysql_stmt_prepare() Prepares a statement.
mysql_stmt_reset() Resets a statement buffer on the server.
mysql_stmt_result_metadata() Returns the metadata of a prepared statement as a result set.
mysql_stmt_row_seek() Searches for an arbitrary row in the result set of a prepared statement.
mysql_stmt_row_tell() Returns the current position of the row cursor for the result set of a prepared statement.
mysql_stmt_send_long_data() Sends data to the server in pieces.
mysql_stmt_sqlstate() Returns the SQLSTATE value for the most recently called statement API function.
mysql_stmt_store_result() Retrieves and stores a result set.
mysql_store_result() Retrieves and stores a result set.
mysql_thread_end() Finalizes the thread handler.
mysql_thread_id() Returns the current thread ID.
mysql_thread_init() Initializes the thread handler.
mysql_thread_safe() Indicates whether the client library is compiled as thread-safe.
mysql_use_result() Retrieves a result set row by row.
mysql_warning_count() Returns the number of alerts generated during the execution of the previous statement.

Example

Use basic APIs to connect to OceanBase Database, create a table, and modify the data in the table.

mysql_library_init(0, NULL, NULL);
MYSQL *mysql = mysql_init(NULL);

/* Use the CLIENT_MULTI_STATEMENTS option to connect to the server. */
if (mysql_real_connect (mysql, host_name, user_name, password,
    db_name, port_num, socket_name, CLIENT_MULTI_STATEMENTS) == NULL)
{
  printf("mysql_real_connect() failed\n");
  mysql_close(mysql);
  mysql_library_end();
  exit(1);
}

/* Execute multiple statements. */
status = mysql_query(mysql,
                     "DROP TABLE IF EXISTS tbl1;\
                      CREATE TABLE tbl1(id INT);\
                      INSERT INTO tbl1 VALUES(110);\
                      UPDATE tbl1 SET id=120 WHERE id=110;\
                      SELECT * FROM tbl1;\
                      DROP TABLE tbl1");
if (status)
{
  printf("Could not execute statement(s)");
  mysql_close(mysql);
  mysql_library_end();
  exit(0);
}

/* Process the result of each statement. */
do {
  /* Check whether the current statement returns data. */
  result = mysql_store_result(mysql);
  if (result)
  {
    /* If yes, process the rows and release the result set. */
    process_result_set(mysql, result);
    mysql_free_result(result);
  }
  else          /* No result set generated or an error occurred. */
  {
    if (mysql_field_count(mysql) == 0)
    {
      printf("%lld rows affected\n",
            mysql_affected_rows(mysql));
    }
    else  /* An error occurred. */
    {
      printf("Could not retrieve result set\n");
      break;
    }
  }
  /* Check whether more results are generated.  The value -1 indicates no. The value 0 indicates yes, which means the loop continues. A value greater than 0 indicates that an error occurred. */
  if ((status = mysql_next_result(mysql)) > 0)
    printf("Could not execute statement\n");
} while (status == 0);

mysql_close(mysql);
mysql_library_end();

Previous topic

OceanBase Connector/C
Last

Next topic

Connect C applications to OceanBase Database
Next
What is on this page
Overview
Example