Updated on 2023-12-13 GMT+08:00

Creating a Stored Procedure

A stored procedure is a set of SQL statements used to implement specific functions. After being compiled, stored procedures are stored in databases. You can execute the stored procedures by specifying their names and related parameters.

A stored procedure consists of a set of SQL statements that can complete specific tasks or process complex services. This section describes how to create a stored procedure. You can use loop statements in a stored procedure to insert objects repeatedly.

Prerequisites

You have obtained the CREATE PROCEDURE permission.

Procedure

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and project.
  3. Click in the upper left corner, and under Databases, click Data Admin Service.
  4. In the navigation pane on the left, choose Development Tool.

    You can also click Go to Development Tool on the overview page.

  5. Locate the DB instance that you want to log in to and click Log In in the Operation column.
  6. On the top menu bar, choose Database Management.
  7. In the upper area of the page, click Change on the right of the current database to switch to the database where you want to create a stored procedure.

    Figure 1 Switching to the database where you want to create a stored procedure

  8. On the displayed Objects page, select Stored Procedures. In the upper left corner of the page, click Create Stored Procedure.

    Figure 2 Creating a stored procedure

  9. On the displayed page, click Set Template Parameter. In the displayed dialog box, set parameters as required and click OK.

    Figure 3 Setting template parameters

  10. On the page for creating a stored procedure, click Execute.

    Figure 4 Executing a stored procedure

  11. In the displayed dialog box, set input parameters and click Execute.

    Figure 5 Executing

  12. View the execution status on the Message and Result Set tab pages after the execution of the stored procedure.