Example of input and output parameters of mysql Stored Procedure

Source: Internet
Author: User

Example of input and output parameters of mysql Stored Procedure

drop PROCEDURE if exists my_procedure; create PROCEDURE my_procedure(in my_id int,out my_name char) BEGIN   select list_name into my_name from aa_list where list_id=my_id; end; call my_procedure(24,@a); select @a;

Can I enter multiple parameters for a mysql stored procedure? For example

Mysql> DELIMITER //
Mysql> create procedure HelloWorld2 (
-> IN vUserName VARCHAR (10 ),
-> OUT vOutValue VARCHAR (10 ),
-> INOUT vInOutValue VARCHAR (10 ))
-> BEGIN
-> Select concat ('hello', vUserName );
-> SET vOutValue = 'a ';
-> SET vInOutValue = 'B ';
-> END //
Query OK, 0 rows affected (0.00 sec)

Mysql> call HelloWorld2 ('edward ', @ a, @ B )//
+ ----------------------------- +
| CONCAT ('hello', vUserName) |
+ ----------------------------- +
| Hello Edward |
+ ----------------------------- +
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Mysql> select @ //
+ ------ +
| @ A |
+ ------ +
| A |
+ ------ +
1 row in set (0.00 sec)

Mysql> select @ B //
+ ------ +
| @ B |
+ ------ +
| B |
+ ------ +
1 row in set (0.00 sec)
Reference: hi.baidu.com/...1.html

Mysql stored procedure parameters

Table names cannot directly use variables. You can check PREPARE usage more.
Eg:
Drop procedure if exists 'table ';
DELIMITER //
Create procedure 'table' (IN tname varchar (64 ))
BEGIN
SET @ sqlcmd = CONCAT ('select count (1) from', tname );
PREPARE stmt FROM @ sqlcmd;
EXECUTE stmt;
Deallocate prepare stmt;
END //
DELIMITER;
Call table ('test ');

Related Article

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.