Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql basic four stored procedures

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report