mysql写一个存储过程
createprocproc_login@namevarchar(16),@psdvarchar(8),@outintoutputasbegindeclare@passv...
create proc proc_login
@name varchar(16),
@psd varchar(8),
@out int output
as
begin
declare @pass varchar(8)
if exists(select * from [user] where [name]=@name)
begin
select @pass=pass from [user] where [name]=@name
if(@pass =@psd )
set @out=9
else
set @out=1
end
else
set @out=0
end
这个是别人写的sql server 的帮忙转化为mysql的。谢谢 展开
@name varchar(16),
@psd varchar(8),
@out int output
as
begin
declare @pass varchar(8)
if exists(select * from [user] where [name]=@name)
begin
select @pass=pass from [user] where [name]=@name
if(@pass =@psd )
set @out=9
else
set @out=1
end
else
set @out=0
end
这个是别人写的sql server 的帮忙转化为mysql的。谢谢 展开
2个回答
展开全部
这个SQL存储过程改写成MYSQL如下:
CREATE PROCEDURE proc_login
(IN v_name VARCHAR(16),
IN v_psd VARCHAR(8),
OUT v_out INT)
BEGIN
DECLARE v_pass VARCHAR(8);
DECLARE v_num INT;
SELECT COUNT(*) INTO v_num FROM USER WHERE name=v_name;
IF v_num<>=0
SELECT pass INTO v_pass FROM user WHERE name=v_name;
IF v_pass=v_psd
SET v_out=9;
ELSE
SET v_out=1;
END IF;
ELSE
SET v_out=1;
END IF;
END;
希望能帮到你。
CREATE PROCEDURE proc_login
(IN v_name VARCHAR(16),
IN v_psd VARCHAR(8),
OUT v_out INT)
BEGIN
DECLARE v_pass VARCHAR(8);
DECLARE v_num INT;
SELECT COUNT(*) INTO v_num FROM USER WHERE name=v_name;
IF v_num<>=0
SELECT pass INTO v_pass FROM user WHERE name=v_name;
IF v_pass=v_psd
SET v_out=9;
ELSE
SET v_out=1;
END IF;
ELSE
SET v_out=1;
END IF;
END;
希望能帮到你。
追问
IF v_num=0和IF v_pass=v_psd是不是有问题啊,怎么老是创建不成功呢,你试了没啊?我的mysql是5.5的。
追答
额,不要意思i,写完没测试,少写了2个THEN,正确语句如下:
CREATE PROCEDURE proc_login
(IN v_name VARCHAR(16),
IN v_psd VARCHAR(8),
OUT v_out INT)
BEGIN
DECLARE v_pass VARCHAR(8);
DECLARE v_num INT;
SELECT COUNT(*) INTO v_num FROM USER WHERE name=v_name;
IF v_num0 THEN
SELECT pass INTO v_pass FROM user WHERE name=v_name;
IF v_pass=v_psd THEN
SET v_out=9;
ELSE
SET v_out=1;
END IF;
ELSE
SET v_out=1;
END IF;
END;
这个没问题 ,我测试过。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询