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 Developer Center

V4.1.0Community Edition

  • Document Overview
  • What's New
    • What's new
  • Overview
    • What is ODC?
    • Benefits
    • Architecture
    • Features
    • Limits
  • Quick Start
    • Overview
    • Install ODC
    • Log on to ODC with an account
    • Create a private connection
  • Tutorials
    • Tips on the SQL Console
    • Create a connection
    • Export data
    • Import data
    • Debug a stored procedure
    • View the performance of an SQL statement
  • User Guide (Web ODC)
    • Log on to ODC
      • Log on to ODC with an account
      • Change the password
    • ODC homepage
    • Connect to a database
      • Create a private connection
      • Manage private connections
    • Public resource management
      • Overview
      • Quick start
      • Resource permissions
        • Manage public connections
        • Manage resource groups
        • Manage roles
        • Manage users
        • Automatic authorization rules
      • Task process management
      • Manage operation records
      • Data desensitization management
      • System settings
    • Use the workspace
      • Overview
      • SQL window
      • Anonymous block window
      • Command-line window
      • Stored scripts
      • Snippet
    • Use tools
      • Data export and import
        • Overview
        • Export and import formats
        • Batch export and import
        • Single table export and import
      • Data mocking
      • Partitioning plan
      • Database changes
      • Shadow table synchronization
      • SQL plan
    • Recycle bin
    • View operation records
    • Task management
      • Overview
      • Import tasks
      • Export tasks
      • Data mocking tasks
      • Database change tasks
      • Partitioning plan task
      • Permission application tasks
      • Shadow table synchronization tasks
      • SQL plan task
    • Session management
    • Database objects
      • Table objects
        • Create a table
        • Create a table
        • Table list
        • Manage table attributes
        • Manage table data
      • View objects
        • Overview
        • Create a view
        • Manage views
      • Function objects
        • Overview
        • Create a function
        • Manage functions
      • Stored procedure objects
        • Overview
        • Create a stored procedure
        • Manage stored procedures
      • Sequence objects
        • Overview
        • Create a sequence
        • Manage sequences
      • Package objects
        • Overview
        • Create a program package
        • Manage program packages
      • Trigger objects
        • Overview
        • Create a trigger
        • Manage triggers
      • Type objects
        • Overview
        • Create a type
        • Manage types
      • Synonym objects
        • Overview
        • Create a synonym
        • Manage synonyms
    • Help center
  • User Guide (Client ODC)
    • Install ODC
    • ODC homepage
    • Connect to a database
      • Create a private connection
      • Manage connections
    • Use the workspace
      • Overview
      • SQL window
      • Anonymous block window
      • Command-line window
      • Stored scripts
      • Snippet
    • Use tools
      • Data export and import
        • Overview
        • Export and import formats
        • Batch export and import
        • Single table export and import
      • Data mocking
      • Asynchronous execution
      • Shadow table synchronization
    • Recycle bin
    • View operation records
    • Task management
      • Overview
      • Import tasks
      • Export tasks
      • Data mocking tasks
      • Database Change
      • Shadow table synchronization tasks
    • Session management
    • Database objects
      • Table objects
        • Overview
        • Create a table
        • Table list
        • Manage table attributes
        • Manage table data
      • View objects
        • Overview
        • Create a view
        • Manage views
      • Function objects
        • Overview
        • Create a function
        • Manage functions
      • Stored procedure objects
        • Overview
        • Create a stored procedure
        • Manage stored procedures
      • Sequence objects
        • Overview
        • Create a sequence
        • Manage sequences
      • Package objects
        • Overview
        • Create a program package
        • Manage program packages
      • Trigger objects
        • Overview
        • Create a trigger
        • Manage triggers
      • Type objects
        • Overview
        • Create a type
        • Manage types
      • Synonym objects
        • Overview
        • Create a synonym
        • Manage synonyms
    • Help center
  • Deployment Guide
    • Deployment overview
    • Preparations before deployment
    • Deploy a single ODC node
      • Deployment process
      • Load and run an ODC image
    • Deploy ODC in high availability mode
      • Deployment process
      • Load and run an ODC image
      • Deploy SSL certificate
      • Deploy the NGINX proxy
      • Configure certificate trust
    • Deployment verification
  • Upgrade Guide
    • Overview
    • Preparations before upgrade
    • Upgrade single-node ODC
      • Upgrade process
      • Stop ODC of the earlier version
      • Load and run an ODC image
    • Upgrade high-availability
      • Upgrade process
      • Stop ODC of the earlier version
      • Load and run an ODC image
      • Upgrade NGINX image
    • Upgrade verification
    • Rollback after upgrade failed
  • FAQ

Download PDF

Document Overview What's newWhat is ODC? Benefits Architecture Features Limits Overview Install ODC Log on to ODC with an account Create a private connection Tips on the SQL Console Create a connection Export data Import data Debug a stored procedure View the performance of an SQL statement Log on to ODC with an account Change the password ODC homepageCreate a private connection Manage private connections Overview Quick start Task process managementManage operation records Data desensitization managementSystem settings Overview SQL windowAnonymous block window Command-line window Stored scripts Snippet Data mocking Partitioning planDatabase changes Shadow table synchronization SQL planRecycle bin View operation records Overview Import tasks Export tasks Data mocking tasks Database change tasks Partitioning plan task Permission application tasks Shadow table synchronization tasks SQL plan taskSession management Help center Install ODC ODC homepage Create a private connection Manage connections Overview SQL windowAnonymous block window Command-line window Stored scripts Snippet Data mocking Asynchronous execution Shadow table synchronizationRecycle bin View operation records Overview Import tasks Export tasks Data mocking tasks Database Change Shadow table synchronization tasksSession management Help center Deployment overview Preparations before deployment Deployment process Load and run an ODC image Deployment process Load and run an ODC image Deploy SSL certificate Deploy the NGINX proxy Configure certificate trust Deployment verificationOverview Preparations before upgrade Upgrade process Stop ODC of the earlier version Load and run an ODC image Upgrade process Stop ODC of the earlier version Load and run an ODC image Upgrade NGINX image Upgrade verification Rollback after upgrade failed FAQ
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 Developer Center
  3. V4.1.0
iconOceanBase Developer Center
V 4.1.0Community Edition
  • V 4.4.2
  • V 4.4.1
  • V 4.4.0
  • V 4.3.4
  • V 4.3.3
  • V 4.3.2
  • V 4.3.1
  • V 4.3.0
  • V 4.2.4
  • V 4.2.3
  • V 4.2.2
  • V 4.2.1
  • V 4.2.0
  • V 4.1.3 and earlier
Community Edition
  • V 4.1.0
  • V 4.0.0
  • V 3.3.2
  • V 3.2.2
Enterprise Edition
  • V 4.1.3
  • V 3.4.0

Create a function

Last Updated:2023-09-05 07:45:46  Updated
share
What is on this page
Overview
Procedure
Step 1: Specify the function name.
Step 2: Specify the data type of the return value.
Step 3: Specify parameters.
Step 4: Verify the parameters of the new function.
Step 5: Edit the function.
Step 6: Complete the function creation.
Related topics

folded

share

ODC supports visualized function creation. This topic describes how to create a function with ODC.

Overview

A function is a subprogram defined in a database. You can call functions by using built-in SQL statements. If the built-in functions cannot meet your business requirements, OceanBase Developer Center (ODC) allows you to create functions. User-defined functions not only help you perform some calculations and special operations, but also reduce coding redundancy to improve the program readability.

A function is a procedural object that is similar to a stored procedure in a database. Like a stored procedure, a function is a code snippet of SQL statements and procedural statements, and can be called by applications and other SQL statements.

Differences between a user-defined function and a stored procedure:

  • A function returns only one result and is suitable for data processing that generates one result. A stored procedure may return zero or multiple results and is suitable for batch insertion and batch update.

  • You can call a function by using a SELECT statement. You can call a stored procedure by using a CALL statement.

Create a function 1

As shown in the preceding figure, you can create a function in the following six steps:

  1. Specify the function name.

  2. Specify the data type of the return value.

  3. Specify parameters.

  4. Verify the parameters of the new function.

  5. Edit the function.

  6. Complete the function creation.

Procedure

In the following example, a function named function_emp is created in the ODC console to obtain the employee name from an employee table based on the employee ID. The function_emp function contains an INT type id parameter. Procedure:

Step 1: Specify the function name.

Log on to the ODC console and click the name of a connection to go to the corresponding connection management page. You can click Function in the left-side navigation pane to get a list of functions. To create a function, click + in the upper-right corner of the function list or click Create in the top navigation bar.

1

Step 2: Specify the data type of the return value.

Step 3: Specify parameters.

  1. Parameters specify the information passed to a function when the function is called.

    • In Oracle mode, specify the following fields: Name, Mode, Type, and Default Value.

    • In MySQL mode, specify the following fields: Name, Type, and Length.

  2. You can specify parameters by using one of the following three methods.

Method Description
Use the quick access toolbar In the quick access toolbar, you can add, delete, and move up and down parameters.
Click the row number - You can click a row number to select a row and display the quick access toolbar that allows you to delete the row or move the row up or down.
- You can click a row number to select the row, and then drag the row to adjust its order.
Right-click Right-click the mouse to select the entire row, copy row or move down the row.
  1. You need to specify the mode for the parameters.

    The parameter mode setting is unavailable in MySQL mode. The Oracle mode supports the following parameter modes: IN, OUT, and INOUT.

Parameter Type
IN Indicates an input parameter. When a function is called, the input parameter is passed to the function and used in the execution of the function.
OUT Indicates an output parameter. When a function is called, the value of the output parameter is ignored and an empty value is passed to the function. The output parameter in the function body can be modified. The modified result is returned and passed to the argument that the output parameter represents.
INOUT Indicates an inout parameter. An inout parameter is both an input parameter and an output parameter.

Note
In Oracle mode, both functions and stored procedures support IN, OUT, and INOUT modes. In MySQL mode, functions support only IN mode, and stored procedures support IN, OUT, and INOUT modes.

Step 4: Verify the parameters of the new function.

Click OK to go to the Create Function page.

Step 5: Edit the function.

5

Edit the function statement on the Create Function page. You can edit the SQL statements of the created function on the Create Function page. Syntax:

CREATE FUNCTION < function name > ([ <parameter 1> <type 1> [ , <parameter 2> <type 2>] ] …)
RETURNS < type >
< function body >

Parameters

Parameter Description
< function name > The name of the user-defined function.
Notice
The name of a user-defined function cannot be the same as that of a stored procedure.
< parameter >< type > Parameters of the function. This field contains only the name and type. You cannot specify the IN, OUT, or INOUT keyword.
RETURNS< type > The data type of the return value. <type> specifies the data type of the return value.
Notice
The SELECT statement in a RETURN VALUE statement returns only a single-row and single-column value.
< function body > The body of the user-defined function. The function body must contain a RETURN <value> statement, where <value> specifies the return value of the user-defined function.

Example:

CREATE FUNCTION `function_emp` ( `id` int(45)) RETURNS VARCHAR(300)

-- The start of the function body.
BEGIN

-- Declare a variable.
DECLARE
  a VARCHAR(300);

-- Assign a value to the variable.
SELECT
  name INTO a
FROM
  employee
WHERE
  emp_no = id;

-- The return value.
RETURN a;

-- The end of the function body.
END

Step 6: Complete the function creation.

Click Create in the upper-right corner to create the function. After a user-defined function is created, you can use the SELECT statement to call it, just like how you call a built-in function.

Note
To manage a function, right-click the function name in the left-side navigation pane, and select the required operation from the context menu, which provides the following options: View, Create, Edit, Compile, Debug, Run, Download, Delete, and Refresh. Edit , Compile , and Debug are not supported in MySQL mode. For more information, see Manage functions.

Syntax:

SELECT <function name> ([<parameter> [,...]])

Example:

SELECT function_emp(2);
  • MySQL mode

    6.1

  • Oracle mode

    6.2

    Notice

    • In Oracle mode, if a user-defined function contains an OUT parameter, you must call the function by using the CALL statement.
    • A yellow icon in the function list indicates an error or alert.

Related topics

Create a table Create a view Create a stored procedure Create a sequence Create a program package Create a trigger Create a type Create a synonym

Previous topic

Overview
Last

Next topic

Manage functions
Next
What is on this page
Overview
Procedure
Step 1: Specify the function name.
Step 2: Specify the data type of the return value.
Step 3: Specify parameters.
Step 4: Verify the parameters of the new function.
Step 5: Edit the function.
Step 6: Complete the function creation.
Related topics