MySQL SELECT,存储在变量中
对于存储过程,我想要执行 SELECT,并将列的值存储到变量中。
我该怎么做?
我想做这样的事情:
DECLARE countTemp INT;
SET countTemp=(SELECT COUNT(Name) FROM mytable WHERE Name= var_name LIMIT 0,1);
或者,像这样:
DECLARE countTemp INT;
SELECT countTemp=ColumnXYZ FROM mytable WHERE Name= var_name LIMIT 0,1;
但是,我尝试了这些,MySQL 说我的语法不正确;我该怎么做这样的事情?
For a stored procedure, I want to do a SELECT, and store a column's value into a variable.
How do I do this?
I want to do something like this:
DECLARE countTemp INT;
SET countTemp=(SELECT COUNT(Name) FROM mytable WHERE Name= var_name LIMIT 0,1);
OR, like this :
DECLARE countTemp INT;
SELECT countTemp=ColumnXYZ FROM mytable WHERE Name= var_name LIMIT 0,1;
But, I tried these and MySQL says my syntax is incorrect; how do I do something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样:
http://www.java2s.com/Code/SQL /过程-函数/Useselectintoto将值分配给Integervariable.htm
Like this :
http://www.java2s.com/Code/SQL/Procedure-Function/UseselectintotoassignvaluetoanIntegervariable.htm
您可以轻松地在选择查询中设置变量
@countTemp 是您的变量!
You can easily set the variable in the select query
@countTemp is your variable!