标签:
MySQL 真心不如sqlserver灵活
存储过程注意事项:
1.declare 依次声明
DECLARE MyAccountID VARCHAR (36);
DECLARE Balance DECIMAL (18, 2) DEFAULT 0.00;
DECLARE Operator VARCHAR (36) DEFAULT ‘168A65D2-7FF7-4865-84EF-C41560F4D8D5‘;
DECLARE TypeName VARCHAR (200);
如果有默认值 用default ,如果要赋值,在变量全部声明完之后,用set
SET TypeName = (
CASE Type
WHEN 1 THEN
‘充值‘
ELSE
‘扣款‘
END
);
尽量不要set之后,再declare,会有莫名的错误
2. 在一大段sql语句(select * from.... , insert into .....)之后,如果要给变量赋值用select
SELECT (
CASE Type
WHEN 1 THEN
Balance + Money
WHEN 0 THEN
Balance - Money
ELSE
0
END
) into Balance;
此处我用set 赋值怎么搞都报错。。。
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘ at line 186
set 单独执行没有错,放在这里就不行了。。。。。反反复复试,才找到原因,真他妈坑比呀。
-- 判断账号资金是否异常
IF Type <> 3 THEN
SELECT
‘2‘;
ELSEIF Type = 3 THEN
SELECT
‘3‘;
ELSE
SELECT
‘1‘;
END
IF;
标签:
原文地址:http://www.cnblogs.com/wei-lai/p/5130414.html