MYSQL PL/SQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.