MySQL stored procedure details mysql stored procedure and mysql stored procedure details

Source: Internet
Author: User

MySQL stored procedure details mysql stored procedure and mysql stored procedure details

/* Create a stored procedure */
/* Specify an ending mark before creating a stored procedure */
DELIMITER $
CREATE PROCEDURE test_pro1()
BEGIN
SELECT * FROM address;
END $
/* CALL the Stored Procedure */CALL test_prol ();
DELIMITER $
CREATE PROCEDURE test_pro1()
BEGIN
SELECT * FROM address;
SELECT * FROM book;
END $
CALL test_pro2();
/* Stored procedures with Parameters
IN: indicates the input parameter, which can carry data to the stored procedure.
OUT: return parameters. results can be returned from stored procedures.
INOUT: indicates the input and output parameters. Both parameters and results can be returned.
*/
DELIMITER $
CREATE PROCEDURE test_pro_in(IN id INT)
BEGIN
select * from address where id=id;
END $
CALL test_pro_in(7369);
/* Stored procedure with multiple input parameters
*/\
DELIMITER $
CREATE PROCEDURE test_pro_inmore(IN id INT,IN id2 INT)
BEGIN
SELECT * FROM address WHERE empno=id OR empno=id2;
END $
 CALL test_pro_inmore(7369,7499);
DELIMITER $
CREATE PROCEDURE test_pro_out(OUT num INT)
BEGIN
/* Assign a value to the output parameter. The keyword is set */
SET num=10;
END $ 
CALL test_pro_out (@ val); // The local variable is the session variable, and the session variable starts with the @ symbol.
SELECT @val;
/* Mysql database VARIABLES: 1. Global VARIABLES 2. Local VARIABLES 3. Session VARIABLES */show variables; // query all global VARIABLES
Show variables like 'Char % '// fuzzy query global VARIABLES
Select character_set_client; // global variable of a single query
Set @ vail = 'Peter '; // you must specify a value when defining a session variable!
select @vail;
// The Value of the local variable is DELIMITER between begin and end $
CREATE PROCEDURE test_pro_loc()
 
BEGIN
DECLARE i INT DEFAULT 1;
END $
// Stored procedure with input and output parameters, keyword inout
DELIMITER $
CREATE PROCEDURE test_pro_inout(INOUT n INT)
BEGIN
SET n=100;
END $
SET @aaaaa=10000;
SELECT  @aaaaa;
CALL test_pro_inout(@aaaaa);
SELECT @aaaaa;
 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.