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.3.1

  • Overview
    • What is ODC?
    • Features
    • Architecture
    • Limitations
    • ODC console
  • Quick Start
    • Client ODC
      • Overview
      • Install Client ODC
      • Use Client ODC
    • Web ODC
      • Overview
      • Deploy Web ODC
      • Use Web ODC
  • Data Source Management
    • Create a data source
    • Data sources and project collaboration
    • Database O&M
      • Session management
      • Global variable management
      • Recycle bin management
  • SQL Development
    • SQL editing and execution
    • Perform PL compilation and debugging
    • Use the command-line window
    • Edit and export the result set of an SQL statement
    • Execution analysis
    • Generate test data
    • Database objects
      • Table objects
        • Overview
        • Create a table
        • Manage tables
      • 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
  • Import and Export
    • Import schemas and data
    • Export schemas and data
  • Database Change Management
    • User Permission Management
      • Users and roles
      • Automatic authorization
    • Project collaboration management
    • Risk levels, risk identification rules, and approval processes
    • SQL check specifications
    • SQL window specification
    • Database change management
    • Logical database change management
    • Batch database change management
    • Lock-free schema changes
    • Synchronize shadow tables
    • Schema comparison
  • Data Lifecycle Management
    • Archive data
    • Clean up data
    • Partitioning Plan Management
      • Manage partitioning plans
      • Set partitioning strategies
      • Examples
    • SQL plan task
  • Data Desensitization and Auditing
    • Desensitize data
    • Operation records
  • Notification Management
    • Overview
    • View notification records
    • Manage Notification Channel
      • Create a notification channel
      • View, edit, and delete a notification channel
      • Configure a custom channel
    • Manage notification rules
  • System Integration
    • Login integration
    • Approval integration
    • SQL approval integration
  • Deployment Guide
    • Deployment overview
    • Preparations before deployment
    • Load and run an ODC image
    • Deploy ODC in high-availability mode
    • Deployment verification
  • Upgrade Guide
    • Upgrade Overview
    • Preparations before upgrade
    • Update single-node ODC
    • Update high-avaliability ODC
    • Upgrade verification
    • Rollback after upgrade failed
  • Troubleshooting
    • ODC troubleshooting process
    • Collect Message
      • View the runtime environment and version information
      • View web ODC logs
      • View client ODC logs
      • View end-to-end ODC-related logs
      • View ODC MetaDB data
      • Query the index status in OceanBase Database V4.x
      • Query the index status in OceanBase Database V1.4.x to V3.2.x
      • Collect JVM runtime information
      • Use tcpdump to capture packets
    • Common Troubleshooting
      • Deployment Upgrade
        • Web ODC cannot be accessed after startup
      • Database Connection
        • Access denied in a connection trial or test
        • Connection is refused in a connection trial or test
        • Connection times out
        • `Connection reset` is reported for a time-consuming statement
        • `socket write error` or `closed by server` is reported for a connection
      • SQL Execution
        • Disconnection during SQL execution
        • `Over tenant memory limits` is reported during SQL execution
        • `Unknown thread id` is returned during SQL execution
        • `timeout` errors returned during SQL execution
        • `OutOfMemoryError` is returned during SQL execution
        • Incomplete result columns for the SELECT statement
        • Garbled Chinese characters in the SQL execution result set
        • Garbled Chinese data is returned for query of data in GBK encoding
      • PL Object
        • Debugging is not supported for invalid PL objects
        • `JSONException` is reported during PL debugging
        • Garbled variable values in debugging
        • Failed to view PL objects or garbled characters are returned
        • PL objects cannot be executed or an execution error is returned
        • ODC issues during PL debugging
        • PL anonymous block cannot be debugged
        • Alert information of a PL object is unavailable
      • Import and Export
        • Garbled Chinese characters in an imported file in GBK encoding
        • Invalid ZIP package reported during file import
        • Time-type data exported from an Oracle tenant cannot be imported
        • Mismatched columns reported during the import of a single-table CSV file
        • Failed to export a result set in ODC to an Excel file
        • Incorrect display in Excel for a result set exported in CSV format
        • Incomplete data in batch export of multiple tables
        • `javax.crypto.BadPaddingException: Given final block not properly padded` is returned for a data import or export failure
      • Client ODC Problems
        • Client ODC startup failure / H2 Database corruption: Chuck not found
        • Garbled Chinese characters in the command-line window of ODC
        • Failed to install client ODC
        • Client ODC startup failure or no response
        • `Not a valid secret key` is returned for connection creation in client ODC
        • `User does not exist` returned for connection creation in client ODC
        • High memory usage of client ODC
        • Client ODC fails to be installed or start due to a port conflict
      • Front Page Exception
        • JavaScript exception is thrown on the ODC page
        • No response in browser after opening ODC
        • White screen in ODC
      • Account Password Problem
        • Forgot the admin account password in ODC V3.2.0 or later
        • Forgot an account password in ODC V2.4.1 to V3.1.3
        • Forgot an account password in ODC V2.4.0 or earlier
    • FAQ
      • Installation of client ODC
      • Web ODC deployment and startup
      • FAQ
      • Command-line window
      • DDL statement display
  • Release Note
    • V4.3
      • ODC V4.3.2
      • ODC V4.3.1
      • ODC V4.3.0
    • V4.2
      • ODC V4.2.4
      • ODC V4.2.3
      • ODC V4.2.2
      • ODC V4.2.1
      • ODC V4.2.0
    • V4.1
      • ODC V4.1.3
      • ODC V4.1.2
      • ODC V4.1.1
      • ODC V4.1.0
    • V4.0
      • ODC V4.0.2
      • ODC V4.0.0
    • V3.4
      • ODC V3.4.0
    • V3.3
      • ODC V3.3.3
      • ODC V3.3.2
      • ODC V3.3.1
      • ODC V3.3.0
    • V3.2
      • ODC V3.2.3
      • ODC V3.2.2
      • ODC V3.2.1
      • ODC V3.2.0

Download PDF

What is ODC? Features Architecture Limitations ODC console Overview Install Client ODC Use Client ODC Overview Deploy Web ODC Use Web ODC Create a data source Data sources and project collaboration Session management Global variable management Recycle bin management SQL editing and execution Perform PL compilation and debugging Use the command-line window Edit and export the result set of an SQL statement Execution analysis Generate test data Import schemas and data Export schemas and data Users and roles Automatic authorization Project collaboration management Risk levels, risk identification rules, and approval processes SQL check specifications SQL window specification Database change management Logical database change management Batch database change management Lock-free schema changes Synchronize shadow tables Schema comparison Archive data Clean up data Manage partitioning plans Set partitioning strategies Examples SQL plan task Desensitize data Operation records Overview View notification records Create a notification channel View, edit, and delete a notification channel Configure a custom channel Manage notification rules Login integration Approval integration SQL approval integrationDeployment overview Preparations before deployment Load and run an ODC image Deploy ODC in high-availability modeDeployment verification Upgrade OverviewPreparations before upgrade Update single-node ODC Update high-avaliability ODCUpgrade verification Rollback after upgrade failed ODC troubleshooting process View the runtime environment and version information View web ODC logsView client ODC logsView end-to-end ODC-related logsView ODC MetaDB dataQuery the index status in OceanBase Database V4.xQuery the index status in OceanBase Database V1.4.x to V3.2.xCollect JVM runtime informationUse tcpdump to capture packetsInstallation of client ODCWeb ODC deployment and startupFAQCommand-line windowDDL statement display ODC V4.3.2 ODC V4.3.1 ODC V4.3.0 ODC V4.2.4 ODC V4.2.3 ODC V4.2.2 ODC V4.2.1 ODC V4.2.0 ODC V4.1.3 ODC V4.1.2 ODC V4.1.1 ODC V4.1.0 ODC V4.0.2 ODC V4.0.0ODC V3.4.0ODC V3.3.3 ODC V3.3.2 ODC V3.3.1 ODC V3.3.0 ODC V3.2.3 ODC V3.2.2
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.3.1
iconOceanBase Developer Center
V 4.3.1
  • 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

Create a stored procedure

Last Updated:2024-11-08 08:55:33  Updated
share
What is on this page
Overview
Differences between a stored procedure and a function
Benefits of stored procedures
Procedure
Step 1: Specify the name of the stored procedure.
Step 2: Specify parameters.
Step 3: Verify the parameters of the stored procedure.
Step 4: Edit the stored procedure.
Step 5: Complete the stored procedure creation.
Related topics

folded

share

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

Overview

A stored procedure is a collection of one or more statements. To perform a series of complex operations on a database, you can use a stored procedure to encapsulate these complex operations into a reusable code block in the database. It helps developers reduce their workload.

In OceanBase Database, a stored procedure is a collection of SQL statements for implementing a specific feature. After you compile and store a stored procedure in the database, you can specify the stored procedure name and the required parameters to call this stored procedure for accelerated execution of the SQL statements.

A stored procedure can contain parameters and return values.

Differences between a stored procedure and a function

  • The return value of a function is a specific result value, while the return value of a stored procedure only indicates whether the execution is successful.

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

Benefits of stored procedures

  • Improve the versatility and portability of the application: After you create a stored procedure, it can be repeatedly called by a program without rewriting the SQL statements of the procedure. In addition, stored procedures can be modified with no impact on the program source code, thereby improving the portability of the program.

  • Accelerate SQL execution: If an operation involves a large amount of SQL statements or repeated execution of the same SQL statements, you can compile the code into a stored procedure and execute the stored procedure, which is faster than separately executing the statements.

  • Alleviate the workload of the server: If one SQL statement is called at a time to perform operations on the database objects, a large number of SQL statements are transmitted. If an equivalent stored procedure, only the command for calling the procedure is sent, thereby reducing the network load.

Overview

As shown in the preceding figure, you can create a stored procedure in the following five steps:

  1. Specify the name of the stored procedure.

  2. Specify parameters.

  3. Verify the parameters of the stored procedure.

  4. Edit the parameters of the stored procedure.

  5. Complete the stored procedure creation.

Procedure

In the following example, a stored procedure named proc_total is created in the ODC console for the calculation of department budgets. The stored procedure contains two INT type input parameters budget_r and budget_s and calculates the sum of the two parameters. Procedure:

Step 1: Specify the name of the stored procedure.

Log on to the ODC console and click the name of the desired connection to go to the corresponding connection management page. You can click Stored Procedure in the left-side navigation pane to get a list of stored procedures. To create a stored procedure, click + in the upper-right corner of the Stored Procedure list or choose Create > Stored Procedure in the top navigation bar.

In the Create Stored Procedure dialog box, enter a name for the stored procedure.

1

Step 2: 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 Name, Mode, 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
  • Copy a row or move one row down: Drag the pointer to select a row, right-click it, and then select Copy or Move Down from the context menu that appears.
  • Copy a cell: Select a cell, right-click it, and then select Copy from the context menu that appears.

Note

After copying a row, you can select a row and paste the copied row data with the shortcut keys Command + V / Ctrl + V.

  1. You need to specify the mode for the parameters.

    OceanBase Database in both MySQL mode and Oracle mode supports the following parameter modes: IN, OUT, and INOUT.

    CREATE PROCEDURE proc_name ([[IN |OUT |INOUT ] parameter_name parameter_type...])
    
    • Parameters

      Parameter Type
      IN Indicates an input parameter.
      When a stored procedure is called, the input parameter is passed to the stored procedure and used in the execution of the stored procedure. Usually, input parameters are only used to pass values in, and are not modified or returned in the call of a stored procedure.
      OUT Indicates an output parameter.
      When a stored procedure is called, the value of an output parameter is ignored and an empty value is passed to the stored procedure. The value of the output parameter is modified during the execution of the stored procedure. After the execution is complete, the modified value is assigned to the output parameter. Usually, output parameters are used to obtain the execution results of a stored procedure. Output parameters can be used to modify and return values in the call of a stored procedure.
      INOUT Indicates an inout parameter.
      An inout parameter is both an input parameter and an output parameter.
    • Parameter settings

      Property Required Default Mode
      Name Yes Empty Oracle/MySQL
      Mode Yes IN Oracle/MySQL
      Type Yes VARCHAR Oracle/MySQL
      Length Yes 45 MySQL
      Default value No Empty Oracle

Step 3: Verify the parameters of the stored procedure.

Click OK to go to the Create Stored Procedure page.

Step 4: Edit the stored procedure.

4

Edit the statements on the Create Stored Procedure page.

In addition, the toolbar on the editing page provides the following buttons.

Button Description
Format Click this button to apply formatting, such as indentation, line break, and keyword highlighting, to the selected SQL statements or all the SQL statements in the current SQL window.
Find and Replace Click this button and enter text in the search field to find the specific content and enter text in the replacement field to replace the content found.
Undo Click this button to undo the last operation.
Redo Click this button to reverse an Undo operation.
Case Sensitivity The system supports three capitalization options: All Caps, All Lowercase, and Capitalize First Letter. Click the corresponding option to convert the selected statements in the script to the desired capitalization format.
Indent You can add indents to or delete indents from the statements that you selected.
Comments You can click Add Comments to convert the statements that you selected into comments or click Delete Comment to convert comments to SQL statements.

You can edit the SQL statements of the created stored procedure on the Create Stored Procedure page. Syntax:

CREATE PROCEDURE proc_name (
  [proc_parameter[,...]])
IS
BEGIN
proc_body:
  Valid SQL routine statement
END [end_label]

Parameters:

Parameter Description
proc_name The name of the stored procedure. By default, a stored procedure is created in the current database. To create a stored procedure in a specific database, add the database name as the prefix to the name of the stored procedure in the format of db_name.sp_name.

Notice

The name of a stored procedure must differ from that of any built-in MySQL function. Otherwise, an error may occur.

[proc_parameter[,…] ] The list of stored procedure parameters. A parameter is specified in the format of [IN|OUT|INOUT] parameter_name parameter_type.
parameter_name specifies the parameter name and parameter_type specifies the parameter type, which can be any valid MySQL data type. If you need to specify multiple parameters, separate them with commas (,). A stored procedure can be created without a parameter. In this case, add a pair of parentheses after the name of the stored procedure.

Notice

The parameter names must differ from the column names in the data table. Otherwise, the SQL statements of the stored procedure may take a parameter name as a column name, which results in errors.

proc_body The body of the stored procedure, which contains the SQL statements to be executed when the stored procedure is called.
The body begins with BEGIN and ends with END. If the body contains only one SQL statement, you can omit the BEGIN and END flags.

Step 5: Complete the stored procedure creation.

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

5.1

Note

To manage a stored procedure, right-click the stored procedure name in the left-side navigation pane, and select the required operation from the context menu, which provides the following options: View, Create, Edit, Run, Download, Delete, and Refresh.For more information, see Manage stored procedures.

Syntax:

CALL proc_name ([proc_parameter [,...]]);

Example:

CALL proc_total (30000, 20000);

5.2

Related topics

  • Create a table
  • Create a view
  • Create a function
  • Create a sequence
  • Create a program package
  • Create a trigger
  • Create a type
  • Create a synonym

Previous topic

Overview
Last

Next topic

Manage stored procedures
Next
What is on this page
Overview
Differences between a stored procedure and a function
Benefits of stored procedures
Procedure
Step 1: Specify the name of the stored procedure.
Step 2: Specify parameters.
Step 3: Verify the parameters of the stored procedure.
Step 4: Edit the stored procedure.
Step 5: Complete the stored procedure creation.
Related topics