The process procedure in MySQL

Source: Internet
Author: User

I. Creating process syntax

CREATE PROCEDURE procedure name (parameter list)

Begin

--SQL statement ...

End

-- create a stored procedure delimiter $$ Create procedure my_act () begin    Select *  from goods; End $ $delimiter;

Second, the review process

-- View All Procedures procedure status [ like ' pattern ']; -- View procedure Creation statements Create procedure process name;

Third, Procedure call

-- procedure calls call procedure name ();

Iv. Process Removal

-- Delete procedure Drop procedure process name;

Five, detailed process parameters
Compared to a function, the parameters of the procedure have more than three qualifier modifiers:

1. In-the value is passed, the parameter can be a number or a variable, and the internal modification of the procedure does not affect the external.

2. Out--reference pass, parameter can only be variable. The data in the pre-use variable will be empty. The value generated in the procedure is passed to the external variable at the end of the procedure call.

3. InOut--Reference pass, parameter can only be a variable. External data can be passed to internal use, internal modifications will also be external. The external value is changed only after the call is finished.

How to use: CREATE PROCEDURE procedure name ([in Parameter name parameter type,][out parameter Name argument type,][inout parameter name, parameter type])

--Creating global VariablesSet @ga = 1;Set @gb = 2;Set @gc = 3;--Sample Process Parametersdelimiter $$Create procedurePro_demo (inchXint, Out Yint, InOut Zint)begin    --view changes after the data entry process    Selectx, y, Z; --Modifying the value of a local variable    SetX=  -; SetY=  $; SetZ=  -; --to view the value of a local variable    Selectx, y, Z; --View the value of a global variable to see if the modification of the local variable has an effect on the global    Select @ga,@gb,@gc; --Modifying the value of a global variable    Set @ga = 'a'; Set @gb = 'b'; Set @gc = 'C'; --View the value of the global variable before the call ends to observe the change to the global variable after the procedure call ends    Select @ga,@gb,@gc;End$ $delimiter;--Call ProcedureCall Pro_demo (@ga,@gb,@gc);--observe the value of the global variable again after the procedure call endsSelect @ga,@gb,@gc;

The process procedure in MySQL

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.