我只想生成 xx 行,每行都有一个数字,类似这样:
SELECT 1 TO 50
结果集包含 50 行,编号从 1 到 50
谢谢
最佳答案
使用存储过程:
delimiter #
create procedure my_counter(lower_bound INT, upper_bound INT)
begin
declare v_max int unsigned default upper_bound;
declare v_counter int unsigned default lower_bound;
CREATE TABLE temp_my_counter (id int);
while v_counter <= v_max do
INSERT INTO temp_my_counter SELECT v_counter;
set v_counter=v_counter+1;
end while;
SELECT temp_my_counter.id FROM temp_my_counter;
DROP TABLE temp_my_counter;
end #
delimiter ;
然后 调用 my_counter(2, 5);
将返回
2
3
4
5
关于MySQL - 生成 xx 行的计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8489024/