MySQL:在存储过程中将多个字段选择为多个变量 [英] MySQL: Selecting multiple fields into multiple variables in a stored procedure

查看:738
本文介绍了MySQL:在存储过程中将多个字段选择为多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在MySQL的同一选择查询中将多个列选择到多个变量中吗?

Can I SELECT multiple columns into multiple variables within the same select query in MySQL?

例如:

DECLARE iId INT(20);
DECLARE dCreate DATETIME;

SELECT Id INTO iId, dateCreated INTO dCreate 
FROM products
WHERE pName=iName;

正确的语法是什么?

推荐答案

您的

Your syntax isn't quite right: you need to list the fields in order before the INTO, and the corresponding target variables after:

SELECT Id, dateCreated
INTO iId, dCreate
FROM products
WHERE pName = iName

这篇关于MySQL:在存储过程中将多个字段选择为多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆