我在mysql updateusers存储过程中遇到了一些问题,如下所示:
DELIMITER go
Create procedure updateusers(
IN UserID tinyint(11),
IN FirstName varchar(30),
IN LastName varchar(30),
IN Password varchar(30),
IN EmailAddress varchar(30),
IN Salt varchar(40),
IN RoleID varchar(1))
BEGIN
update users
set
FirstName = FirstName
where UserID = UserID
End
BEGIN
update users
set
LastName = LastName
where UserID = UserID
End
BEGIN
update users
set
Password = Password
where UserID = UserID
End
BEGIN
update users
set
EmailAddress = EmailAddress
where UserID = UserID
End
BEGIN
update users
set
Salt = Salt
where UserID = UserID
End
BEGIN
update users
set
RoleID = RoleID
where UserID = UserID;
End
go
DELIMITER ;
我在第16行得到一个错误:
MySQL说:文档#1064 - 你的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在
附近使用正确的语法'End BEGIN update users set LastName = LastName where UserID = Us' at line 16
然后我会使用这样的调用存储过程:
call updateusers(3,'John','Jamieson','dsd','jamie@gmail.com','abac123','U')
我想获得的输出是,例如,如果我想更新:
UserId FirstName LastName Password EmailAddress Salt RoleID
3 John Smith abc john@gmail.com 123 U
到此:
UserId FirstName LastName Password EmailAddress Salt RoleID
3 John Jamieson dsd jamie@gmail.com abac123 U
或
UserId FirstName LastName Password EmailAddress Salt RoleID
3 Aaron Smith abc john@gmail.com 123 A
答案 0 :(得分:0)
不可否认,MySQL存储过程的文档从未如此出色。没有足够的例子。
在你的情况下,我会写这样的程序:
DELIMITER go
CREATE PROCEDURE updateusers(
IN inUserID tinyint,
IN inFirstName varchar(30),
IN inLastName varchar(30),
IN inPassword varchar(30),
IN inEmailAddress varchar(30),
IN inSalt varchar(40),
IN inRoleID varchar(1))
BEGIN
UPDATE users
SET
FirstName = inFirstName,
LastName = inLastName,
Password = inPassword,
EmailAddress = inEmailAddress,
Salt = inSalt,
RoleID = inRoleID
WHERE UserID = inUserID;
END
go
DELIMITER ;
的变化:
UPDATE
中更新多个列。实际上,您应该这样做,因此您只需运行一个查询来查找要更新的行。BEGIN...END
,只是在语句块周围,类似于在许多编程语言中使用大括号的方式。UPDATE
语句。tinyint(11)
更改为tinyint
。长度参数不起作用。阅读我对Types in MySQL: BigInt(20) vs Int(20)