--Mysql stored procedure/*set @result = 0;create Procedure Login (--definition parameters, with in, out, inout three types in user varchar (ten), in pass varchar (ten), out result int) BEGIN DECLARE PASSD varchar (ten);--declare declares a temporary variable, type, and then assigns a value using set.declare temporary variables can only be placed in the Begin end Area, and its scope is only in the begin end, and the variable defined by SET @ is a global variable select password into PASSD from login where username=user;if passd like pass and then --if statement, followed by end If, like case also add end case Select ' Login Success ' as massage;set result = 1;elseselect ' login Failed ' As message;set result =0;end if;end;*/--Invoke stored procedure call login (' root ', ' root ', @result);--Delete stored Procedure drop procedure Login creat E procedure translate (id int) begincase idwhen 1 then select ' One ' as Trans;when 2 thenselect ' both ' as Trans;when 3 then Select ' Three ' as Trans;elseselect ' no trans ' as Trans;end case;end; There are two types of/*case usage: 1. The condition variable is in when select name, Casewhen age>10 then Xxxxxelsexxxxxxend case2. Condition variable in case select Name,case agewhen >10 then xxx else xxxxxsend case*/
Stored procedures and cursors in MySQL