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 Service

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 Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Developer Center

V4.4.3
  • Topics Overview
  • 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
    • Edit and execute SQL statements
    • Perform PL compilation and debugging
    • Use the command-line window
    • Edit and export the result set
    • Execution analysis
    • Generate test data
    • System settings
    • Intelligent SQL development
    • Common features
    • Database objects
      • Table objects
        • Overview
        • Create a table
      • View objects
        • Overview
        • Create a view
        • Manage views
      • Materialized view objects
        • Overview
        • Create a materialized view
        • Manage materialized 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
      • External resource objects
        • External resources
        • Create an external resource
        • Manage external resources
  • Database Change Risk Management
    • Project collaborative management
      • Project management
      • Manage databases
      • Manage logical databases
      • Add object storage files
      • Manage project members
      • Desensitize data
      • Notification management
        • Overview
        • View notification records
        • Manage notification channels
          • Create a notification channel
          • View, edit, and delete a notification channel
          • Configure a custom channel
        • Manage notification rules
    • Manage user permissions
      • Users and roles
      • Automatic authorization
      • Apply for project permissions
      • Apply for database permissions
      • Apply table/view permissions
    • Security standards
      • Environment configuration
        • SQL check specifications
        • SQL window specification
      • Risk Management
        • Overview
        • Manage risk identification rules
        • Manage approval processes
      • Desensitization algorithms
      • Operation audit
  • Ticket Management
    • Import schemas and data
    • Export schemas and data
    • Database change management
    • Manage changes to logical databases
    • Batch database change management
    • Online schema changes
    • Synchronize shadow tables
    • Schema comparison
  • Data Lifecycle Management
    • Data archiving
    • Data cleanup
    • Manage partitioning plans
      • Manage partitioning plans
      • Set partitioning strategies
      • Examples of partitioning strategies
    • SQL Plan
  • System Integration
    • Login integration
    • Approval integration
    • SQL approval integration
    • Bastion host integration
    • Integrate with LLMs
  • Deployment Guide
    • Deployment overview
    • Preparations before deployment
    • Deploy ODC in single-node mode
    • Deploy ODC in high-availability mode
    • Deployment verification
  • Upgrade Guide
    • Upgrade Overview
    • Preparations for upgrade
    • Update single-node ODC
    • Update high-avaliability ODC
    • Upgrade verification
    • Rollback after upgrade failed
  • Best Practices
    • Tips for SQL development
    • Explore ODC team workspaces
    • Understanding real-time SQL diagnostics for OceanBase AP
    • OceanBase historical database solutions
    • ODC SQL check for automatic identification of high-risk operations
    • Integration with ODC enterprise-level account system
    • Manage and modify sharded databases and tables via ODC
    • Data masking and control practices
    • Enterprise-level control and collaboration: Safeguard every database change
  • 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
    • FAQ
      • Installation of client ODC
      • Web ODC deployment and startup
      • Connection Information
      • Command-line window
      • DDL statement display
  • Release Notes
    • V4.4
      • ODC V4.4.0
      • ODC V4.4.1
      • ODC V4.4.2
      • ODC V4.4.3
    • V4.3
      • ODC V4.3.4
      • ODC V4.3.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

Document Feedback
  1. Documentation Center
  2. OceanBase Developer Center
  3. V4.4.3

Create a stored procedure

Last Updated:2026-09-03 09:11:30

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

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.

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

Step 2: Specify parameters.

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

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

    • In MySQL compatible 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.

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

    OceanBase Database in both MySQL compatible mode and Oracle compatible 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.

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.

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 and Common features.

Syntax:

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

Example:

CALL proc_total (30000, 20000);

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