My SQL stored procedures are basically used

Source: Internet
Author: User
Tags prepare

--------------Create a stored procedure with no parameters-----------------DELIMITER;;Drop PROCEDURE if EXISTSselectstudent;Create PROCEDURE 'selectstudent'()BEGINSelect* fromstudent;End;;D Elimiter;--------------A stored procedure with parameters--------------------Drop PROCEDURE if EXISTSselectcity;Create PROCEDURE 'selectcity'(inch_cityidvarchar(Ten)--input Parameters--)BEGINSelect * fromStudentwhereCityid=_cityid;End;--------------A stored procedure with an output parameter--------------------Drop PROCEDURE if EXISTSSelectcity_name;CREATE PROCEDURE 'Selectcity_name'(  inch_cityidvarchar(Ten)--input parameters,Out _cityvarchar(Ten)--output parameters,InOut _cityidnamevarchar(Ten)--input and OUTPUT parameters)BEGINSelect* fromStudentwhereCityid=_cityid andCityName=_cityname into_city;End;Set @_cityid='1';Set @_cityidname='Zhengzhou'; call Selectcity_name (@_cityid,@_city,@_cityidname);Select @_cityidname  asId@_city;-----------A stored procedure with wildcard characters------------Drop PROCEDURE if EXISTSSelectcitylike;Create PROCEDURE 'Selectcitylike'(inch_citynamevarchar(Ten))BEGIN Set @exec_sql =CONCAT ("Select * fromStudentwhereName like '% ", _cityname,"%'");PREPAREstmt from @exec_sql;--definitionEXECUTEstmt--executing a preprocessing statementdeallocate PREPAREstmt--Delete DefinitionEnd-------Loop statement: Check results before Operation----------Create PROCEDUREproc4 ()BEGINDeclare var int;Set var=0; while var<6 DoInsert  intoTVALUES(var);Set var=var+1;End  while;End----------Loop statement: Check results after Operation------------Create PROCEDUREproc5 ()BEGINDECLAREVint;SetV=0; REPEATInsert  intoTVALUES(v);SetV=V+1; UNTIL v>=5Endrepeat;End----------Loop statement: Loop. Endloop------------Create PROCEDUREproc6 ()BEGINDeclareVint;SetV=0; Loop_lable:loopInsert  into Values(v);SetV=V+1;ifV>=5  ThenLEAVE loop_lable;End if;EndLoop;End----------Loop statement: Loop. Endloop-------------Create PROCEDUREProc7 ()BEGINDECLAREVint;SetV=0; Loop_lable:loopifV=3  ThenSetV=V+1; Iterate loop_lable;--Continue loopingEnd if;Insert  intoTValues(v);SetV=V+1; ifV>=5  Thenleave loop_lable;--Jump out of the loop  End if;EndLoop;End;

My SQL stored procedures are basically used

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.