MySQL stored procedures, the syntax of the dead

Source: Internet
Author: User

MySQL is really not as flexible as SQL Server

Stored Procedure considerations:

1.declare declarations in turn


DECLARE Myaccountid VARCHAR (36);

DECLARE Balance DECIMAL (2), DEFAULT 0.00;

DECLARE Operator VARCHAR ($) DEFAULT ' 168a65d2-7ff7-4865-84ef-c41560f4d8d5 ';

DECLARE TypeName VARCHAR (200);

If there is a default value, if you want to assign a value, after the variable is all declared, use the set


SET TypeName = (
Case Type
When 1 Then
Recharge
ELSE
' Debit '
END
);

Try not to set, then declare, there will be inexplicable mistakes

2. In a large segment of the SQL statement (SELECT * from ...., insert INTO ...). ), if you want to assign a value to a variable with select


SELECT (
Case Type
When 1 Then
Balance + Money
When 0 Then
Balance-money
ELSE
0
END
) into Balance;

Here I use set to assign value how to make all error ...

You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near "at line 186

Set execution is not wrong, put it here ..... Try again and again, only to find the reason, really his mother pit than AH.

--Determine if the account funds are abnormal
IF Type <> 3 Then
SELECT
' 2 ';


ELSEIF Type = 3 Then
SELECT
' 3 ';


ELSE
SELECT
' 1 ';


END
IF;

MySQL stored procedures, the syntax of the dead

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.