[英]stored procedure mysql returning each result column from each row
I want that The stored procedure returns the value of each column of my select.我希望存储过程返回我选择的每一列的值。
I have customer table with column 1 column 2 and column 3. I have a select wich return 10 rows and I want to get for each row the result of column 1, column2 and column3.我有第 1 列第 2 列和第 3 列的客户表。我有一个返回 10 行的选择,我想为每一行获取第 1 列、第 2 列和第 3 列的结果。
How can i do this我怎样才能做到这一点
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
DECLARE col1 INT DEFAULT 0;
DECLARE col2 VARCHAR(10) DEFAULT "";
DECLARE col3 INT DEFAULT 0;
SELECT COUNT(*) into n FROM customer;
set i=1;
WHILE i<=n DO
SELECT column1 FROM customer WHERE id=i INTO col1;
SELECT column2 FROM customer WHERE id=i INTO col2;
SELECT column3 FROM customer WHERE id=i INTO col3;
SET i = i + 1;
END WHILE;
END
How can i get each value col1,col2 and col3 to display it and to use it for the next treatment.如何获取每个值 col1、col2 和 col3 以显示它并将其用于下一次处理。
How can i call this stored procedure in mysql我如何在 mysql 中调用这个存储过程
Saving your logic you may use保存您可能使用的逻辑
BEGIN
SELECT column1, column2, column3
FROM customer
WHERE id <= ( SELECT COUNT(*)
FROM customer );
END
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.