mysql中存储过程的例子:
CREATE PROCEDURE addvoucher (
IN userid INT,
IN voucherid INT,
OUT result INT
)
BEGIN
SELECT
@endate_a := endate ,@batch_a := batch ,@c_count_a := c_count,
@isdead_a := isdead
FROM
t_voucher
WHERE
id = voucherid
SET autocommit = 0
IF EXISTS (
SELECT
*
FROM
t_user_voucher tuv,
t_voucher tv
WHERE
tv.id = tuv.voucherid
AND tv.batch =@batch_a
) THEN
SET result = 1-- 已存在
SELECT
result
ELSE
IF @c_count_a >0 THEN
IF (
TO_DAYS(@endate_a) - TO_DAYS(NOW())
) >0 THEN
IF @isdead_a = 1 THEN
INSERT INTO t_user_voucher (userid, voucherid, isdead)
VALUES
(userid, voucherid, 1)
UPDATE t_voucher SET c_count = c_count-1 where id = voucherid
SET result = 0-- 成功
END
mysql中要获得存储过程的返回值,可以增加一个out参数,用来返回。mysql中存储过程的例子:
CREATE PROCEDURE addvoucher (
IN userid INT,
IN voucherid INT,
OUT result INT
)
BEGIN
SELECT
@endate_a := endate ,@batch_a := batch ,@c_count_a := c_count,
@isdead_a := isdead
FROM
t_voucher
WHERE
id = voucherid
你好,当你输入一些错误的指令的时候,可能就会导致后面的指令无法继续执行,这个时候一般都是因为引号导致的,可以补全双引号,然后回车,即可结束之前的指令。还有一种办法就是强制结束上一条指令,可以通过快捷键ctrl+c来执行。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)