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 PL/SQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

A set of SQL statements with high speed. Only the first execution needs to go through compilation and optimization steps, and the subsequent calls can be executed directly.

Sample:

DROP PROCEDURE IF EXISTS `proc_ adder`

DELIMITER & &

CREATE DEFINER= `root` @ `localhost` PROCEDURE `proc_ adder` (IN an int, IN b int, OUT sum int)

BEGIN

DECLARE c int

/ * DECLARE c int DEFAULT 10 minutes /

If an is null then set a = 0

End if

If b is null then set b = 0

End if

Set sum = a + b

END

& &

DELIMITER

Description:

DEFINER: creator

DECLARE: defining variabl

SET: assign to a variable

SELECT... The INTO statement assigns values to variables as follows:

SELECT col_name [,...] INTO var_name [,...]

FROM table_name WEHRE condition

DELIMITER:

The default statement Terminator in MySQL is the semicolon (;). The SQL statement in the stored procedure requires a semicolon (;) to end. To avoid conflicts, first set the MySQL Terminator to & & with "DELIMITER & &". Finally, use "DELIMITER;" to restore the Terminator to a semicolon. This is the same as when you create a trigger.

Common syntax:

IF:

IF type = 0 THEN

Set c = 'param is 0'

ELSEIF type = 1 THEN

Set c = 'param is 1'

ELSE

Set c = 'param is others, not 0 or 1'

END IF

CASE:

CASE type

WHEN 0 THEN

Set c = 'param is 0'

WHEN 1 THEN

Set c = 'param is 1'

ELSE

Set c = 'param is others, not 0 or 1'

END CASE

WHILE:

DECLARE i int

DECLARE s int

SET I = 0

SET s = 0

WHILE i

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

Internet Technology

Wechat

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

12
Report