OceanBase logo

OceanBase

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

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

OceanBase

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

Product Overview
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.3.5

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    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.3.5
    iconOceanBase Database
    SQL - V 4.3.5
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • 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

    Stored procedures

    Last Updated:2026-04-15 15:09:26  Updated
    Share
    What is on this page
    Structure of stored procedures
    Creating stored procedures
    Calling stored procedures

    folded

    Share

    A stored procedure is a subprogram that does not directly return a value. When the parameter type is OUT, the stored procedure can also return a value to the caller.

    Structure of stored procedures

    The structure of a PL stored procedure is as follows:

    PROCEDURE sp_name ([proc_parameter[,...]])[characteristic ...]
        BEGIN    -- Start execution
          SQL statement; [ SQL statement; ]...
        END;     -- End execution
    
    proc_parameter:
        [ IN | OUT | INOUT ] param_name type
    
    characteristic: {
        COMMENT 'string'
      | LANGUAGE SQL
      | [NOT] DETERMINISTIC
      | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
      | SQL SECURITY { DEFINER | INVOKER }
    }
    

    Creating stored procedures

    Stored procedures are created by using the CREATE PROCEDURE statement. The significant differences between MySQL mode and Oracle mode are as follows:

    • The DECLARE module must be placed in the BEGIN ... END; module. You can define other statements only after you complete the declaration.

    • You can define DETERMINISTIC / LANGUAGE SQL and other sp_create_chistic information to enrich the usage of stored procedures.

    • Stored procedures in MySQL mode cannot be overloaded.

    Example 1: Create a stored procedure that does not contain IN or OUT parameters.

    obclient> DELIMITER //
    
    obclient> CREATE PROCEDURE proc_name()
       BEGIN
         DECLARE var_name VARCHAR(20) DEFAULT 'ZhangSan';  
         SET var_name = 'LiSi';
         SELECT var_name;
       END //
    Query OK, 0 rows affected
    
    obclient> DELIMITER ;
    
    obclient> CALL proc_name();
    

    The return result is as follows:

    +----------+
    | var_name | 
    +----------+
    | LiSi     |
    +----------+
    1 row in set 
    

    Example 2: Create a stored procedure that contains IN and OUT parameters.

    //Create the emp table as an example.
    obclient> CREATE TABLE emp(
       empno          NUMBER(4,0),
       empname        VARCHAR(10),
       job            VARCHAR(10),
       deptno         NUMBER(2,0),
       salary         NUMERIC
    );
    Query OK, 0 rows affected
    
    obclient> INSERT INTO emp VALUES (200,'Jennifer','AD_ASST',1,15000),(202,'Pat','MK_REP',2,12000),
              (119,'Karen','PU_CLERK', 4,10000),(118,'Guy','PU_CLERK', 4,10000),
             (201,'Michael','MK_MAN',3,9000);
    Query OK, 5 rows affected
    Records: 5  Duplicates: 0  Warnings: 0
    
    obclient> DELIMITER //
    
    obclient> CREATE PROCEDURE my_proc(IN emp_no INT,OUT emp_count INT)
       BEGIN
         SELECT COUNT(*) INTO emp_count FROM emp WHERE empno=emp_no;
       END //
    Query OK, 0 rows affected
    
    obclient> DELIMITER ;
    
    //Initialize parameters
    obclient> SET @emp_no='200',@emp_count=0;
    Query OK, 0 rows affected
    
    //Call the my_proc stored procedure
    obclient> CALL my_proc(@emp_no,@emp_count);
    

    The return result is as follows:

    +-----------+
    | emp_count |
    +-----------+
    |         1 |
    +-----------+
    1 row in set
    

    Continue to view the result after emp_count is assigned:

    obclient> SELECT @emp_count;
    

    The return result is as follows:

    +------------+
    | @emp_count |
    +------------+
    | 1          |
    +------------+
    1 row in set
    

    Calling stored procedures

    You can call a stored procedure by using the CALL statement. However, you cannot call a stored procedure as part of an SQL expression.

    //Call the my_proc stored procedure
    obclient> CALL my_proc(@emp_no,@emp_count);
    Query OK, 0 rows affected
    
    //View the result after emp_count is assigned
    
    obclient> SELECT @emp_count;
    

    The return result is as follows:

    +------------+
    | @emp_count |
    +------------+
    | 1          |
    +------------+
    1 row in set
    

    Previous topic

    Variables in stored programs
    Last

    Next topic

    Stored objects and privilege management
    Next
    What is on this page
    Structure of stored procedures
    Creating stored procedures
    Calling stored procedures