Mysql basic four stored procedures
Stored procedures: declaration and assignment of variables.
Delimiter $
Create procedure p1 ()
Begin
Declare age int default 18; set age: = age+20; or set age = age+20select age from dual
End$
Call the stored procedure: call p1 (); the result is as follows:
Second, stored procedure: if control statement.
Delimiter $
Create procedure p2 ()
Begin
Declare age int default 18 + if age > = 18 then select 'Adult'; else select 'minor'; end if
End$
Call the stored procedure: call p2 (); the result is as follows:
Third, stored procedure: input parameters.
Calculate the area of a rectangle and judge whether it is fat fat? Skinny then? Or square?
Delimiter $
Create procedure p3 (w int, h int)
Begin
Select concat ('area:',w*h)
If w > h then select 'fat';elseif w < h then select' then'; else select 'square';end if
End$
Stored procedure: while loop
Find the sum of 1 to 100.
Delimiter $
Create procedure P100 ()
Begin
Declare total int default 0
Declare num int default 0
While num