a set SQL statement Set, fast, only the first execution needs to be compiled and optimized steps, subsequent calls can be directly executed
S Ample:
DROP PROCEDURE IF EXISTS ' Proc_adder ';
DELIMITER &&
CREATE definer= ' root ' @ ' localhost ' PROCEDURE ' proc_adder ' (in a int, in B int, out sum int)
BEGIN
DECLARE c int;
/* DECLARE C int DEFAULT ten* /
If a is null and then set a = 0;
End If;
If B is null and then set B = 0;
End If;
Set sum = a + b;
END
&&
DELIMITER;
Description
Definer : created by
DECLARE : Defining variables
SET : assigns a variable
SELECT... into The statement assigns a value to the variable as follows:
SELECT col_name[,... ] into var_name[,... ]
From table_name wehre condition
The default statement terminator in MySQL is a semicolon (; ). The SQL statement in the stored procedure requires a semicolon (; ) to end. To avoid conflicts, first use "DELIMITER &&" to set MySQL 's terminator to && . And finally the "DELIMITER;" to restore the Terminator to the component number. 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 <= n do
Set S = s + i;
Set i = i + 1;
END while;
This article is from the "Small Yard Farm" blog, please make sure to keep this source http://daoqingyu.blog.51cto.com/5185063/1950443
MYSQL PL/SQL