Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql basic four stored procedures

Shulou Source: shulou.com Published: 2022-06-01 18:09:48 09月27日 Update

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

Tags: Procedure storage result parameter statement control input output variable adult minor rectangle or area loop foundation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Xiaomi Huawei OPPO Reno MySQL