0 0

这个存储过过程哪里有错啊3

DELIMITER $$

DROP PROCEDURE IF EXISTS `restrant`.`pro_pagination` $$
CREATE PROCEDURE `restrant`.`pro_pagination` (table_name varchar(20),
primary_key varchar(20),
curr_page int,
per_page int)
BEGIN

declare temp varchar(20);
set temp=convert(varchar(10),(curr_page-1)*per_page)
exec(`select top `+per_page+` * from `+table_name+
` where `+primary_key+` not in(select top `+temp+` `+primary_key+
` from `+table_name+` order by `+primary_key+`)`)

exec pro_pagination `foodInfo`,`foodID`,2,5;


END $$

DELIMITER ;
抱的错误是这样的:
Script line: 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(10),(curr_page-1)*per_page)
exec(`select top `+per_page+` * from `+tabl' at line 8
2010年2月19日 14:55

2个答案 按时间排序 按投票排序

0 0

create procedure pro_pagination(table_name varchar(20), primary_key varchar(20), curr_page int, per_page int) begin set @tmpSql=concat('select * from ', table_name,' order by ',primary_key,' limit ', (curr_page-1)*per_page,',',per_page);  prepare stmt from @tmpSql; execute stmt; deallocate prepare stmt;  end

2010年2月22日 16:29
0 0

top应该只在sql中有效。

create procedure pro_pagination(table_name varchar(20), primary_key varchar(20), curr_page int, per_page int) begin set @tmpSql=concat('select * from ', table_name,' order by ',primary_key,' limit ', (curr_page-1)*per_page,',',per_page);  select @tmpSql; prepare stmt from @tmpSql; execute stmt; deallocate prepare stmt;  end

2010年2月22日 16:28

相关推荐

Global site tag (gtag.js) - Google Analytics