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
先定义两个变量,一个入参、一个出参。然后调用就可以了。代码如下;SET @nameid =1
SET @person_name = ''
CALL p3(@nameid, @person_name )
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)