从mysql数据库读取一行并将字段保存到用户定义的变量 [英] Reading a row from mysql database and saving fields to user defined variables
问题描述
嗨
我想知道是否有人对实现以下目标有任何想法:
说我要执行以下操作:
从用户所在位置选择用户名,用户名,用户电话,用户名
现在说我想将上面返回的字段存储到用户定义的变量中.
例如:
SET @Name:= User.Name
SET @Phone:= User.Phone
我该怎么做?
以及如何在mysql中执行if语句.
示例:
如果@Name = John然后插入ADMINTABLE()VALUES()
否则,如果@Name = Paul,然后插入SUPERISOR()VALUES()
我如何实现上述目标?
有没有一种方法可以遍历返回的每一行并针对结果运行函数?
请有人帮忙解决上述任何问题
在此先感谢
Hi
I would like to know if anyone has any idea on how to achieve the following:
Say i do the following:
SELECT User.Name, User.Surname, User.phone FROM User WHERE User.ID = 1
Now say i want to store the fields returned above to user defined variables.
example:
SET @Name := User.Name
SET @Phone := User.Phone
How do i do this??
And how to i do an if statement in mysql.
Example:
If @Name = John THEN INSERT INTO ADMINTABLE() VALUES()
ELSE IF @Name = Paul THEN INSERT INTO SUPERISOR() VALUES()
How do i achieve the above?
And is there a way to iterate thru each row returned and the run functions against results?
Please someone help with any of the above
Thanks in advance
推荐答案
嗨艾希(Ashy)
我认为您可以在select语句中设置一个变量,如下所示:
选择
Hi Ashy
I think you can set a variable inside select statement like this:
SELECT
@Name := User.Name, @Phone := User.phone FROM User WHERE User.ID = 1
检查此 http://dev.mysql.com/doc/refman/5.0/zh-CN /user-variables.html [ ^ ]
要熟悉mysql if else语句,请阅读:
http://dev.mysql.com/doc/refman/5.0/en/if.html [ ^ ]
问候
帕万
如果符合您的条件,请标记答案为解决方案.
check this out http://dev.mysql.com/doc/refman/5.0/en/user-variables.html[^]
To get familiar with mysql if else statement please read this:
http://dev.mysql.com/doc/refman/5.0/en/if.html[^]
Regards
Pawan
Please mark the answer as solution if it fulfills your criteria.
这篇关于从mysql数据库读取一行并将字段保存到用户定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!