mysql默认在语句是不能传参数的,例如 select * from a limit @a,@b;这样是会报错的,那怎么样才能传参数呢?
这就需要用到prepare了,以下示例运行在存储过程
PREPARE statement_name FROM preparable_SQL_statement;/*定义*/ EXECUTE statement_name [USING @var_name [, @var_name] ...]; /*执行预处理语句*/ {DEALLOCATE | DROP} PREPARE statement_name /*删除定义*/ ; -- 实例 set @a=1; set @b=10; PREPARE s1 FROM 'select * from a limit ?,?'; EXECUTE s1 USING @a,@b; DEALLOCATE PREPARE s1;