你要达到什么目的。举例说明 select top @i from BOM 在MYSQL中用LIMIT,字符串累加生成SQL语句,再执行的方法 SET @ASQL=CONCAT('SELECT * FROM TT LIMIT ',@I); PREPARE STML FROM @ASQL; EXECUTE STML
比如: create table teb ( id int PRIMARY key auto_increment not null, name varchar(50) not null ) insert teb(name) select 'test1'; insert teb(name) select 'test2'; select * from teb create PROCEDURE testteb() begin declare a int; declare b int default 1; select count(*) into a from teb; while b<=a DO select * from teb LIMIT b; //相当于top set b=b+1; end while; end call testteb()
在MYSQL中用LIMIT,字符串累加生成SQL语句,再执行的方法
SET @ASQL=CONCAT('SELECT * FROM TT LIMIT ',@I);
PREPARE STML FROM @ASQL;
EXECUTE STML
create table teb
(
id int PRIMARY key auto_increment not null,
name varchar(50) not null
)
insert teb(name) select 'test1';
insert teb(name) select 'test2';
select * from teb
create PROCEDURE testteb()
begin
declare a int;
declare b int default 1;
select count(*) into a from teb;
while b<=a DO
select * from teb LIMIT b; //相当于top
set b=b+1;
end while;
end
call testteb()
mysql 单纯的SQL 语句是不支持使用变量的.