MySQL stored procedure Syntax learning notes

Source: Internet
Author: User

Today, the MySQL stored procedures to learn, we first look at the following code:

A friend who doesn't understand grammar can look at the grammatical structure in detail.

The code is as follows Copy Code

Create PROCEDURE and create FUNCTION Syntax
CREATE
[definer = {User | Current_User}]
PROCEDURE sp_name ([proc_parameter[,...]])
[Characteristic ...] Routine_body

CREATE
[definer = {User | Current_User}]
FUNCTION sp_name ([func_parameter[,...]])
RETURNS type
[Characteristic ...] Routine_body

Proc_parameter:
[In | Out | INOUT] Param_name Type

Func_parameter:
Param_name type

Type
Any valid MySQL data type

Characteristic:
COMMENT ' String '
| LANGUAGE SQL
| [NOT] Deterministic
| {CONTAINS SQL | NO SQL | Reads SQL DATA | Modifies SQL DATA}
| SQL Security {Definer | Invoker}

Routine_body:
Valid SQL Routine statement

Cases

The code is as follows Copy Code

DELIMITER $$/* Change the statement terminator * *

Use ' Test ' $$/* Select Database * *

Drop PROCEDURE if EXISTS ' Outgo ' $$/* exists Outgo stored procedure to delete * *

CREATE definer= ' root ' @ '% ' PROCEDURE ' Outgo ' (in V_table CHAR (Ten), in v_id INT (2), out V_value VARCHAR (32))


The syntax for calling a stored procedure is call.

  code is as follows copy code

mysql> call Outgo (' user ', 2, @a);
+----+--------------+
| id | title&n bsp;       |
+----+--------------+
|  2 | Your big Uncle      |
+----+--------------+
1 row in Set (0.00 SEC)

Query OK, 0 rows Affected (0.00 sec)

mysql> call Outgo (' user ', 1, @a);
+----+--------------------+
| id | title               |
+----+--------------------+
|  1 | I'll test it.        |
+----+------------- -------+
1 row in Set (0.00 sec)

The

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.