写了一个存储过程:
create procedure jt1(title char(10))
begin
set @a=title;
prepare stmt from "select id from pro where ?";
execute stmt using @a;
end
这样调用:call jt1('name="wgh"');
最后输出:Empty set (0.00 sec),并没有得到想要的记录。想到的执行等效这样的语句:select id from pro where name='wgh';
刚学习mysql不知道这样的效果应该怎么实现,哪个大侠帮忙指导一下,谢谢!
create procedure jt1(title char(10))
begin
set @a=title;
prepare stmt from "select id from pro where ?";
execute stmt using @a;
end
这样调用:call jt1('name="wgh"');
最后输出:Empty set (0.00 sec),并没有得到想要的记录。想到的执行等效这样的语句:select id from pro where name='wgh';
刚学习mysql不知道这样的效果应该怎么实现,哪个大侠帮忙指导一下,谢谢!
解决方案 »
- mysql 脚本执行效率请教
- PostgreSQL, N个数据集的比较
- 关于MYSQL问题
- 求一个SQL语句
- 求助,第一个MySQL程序就出问题了
- 一句mssql语句怎么转化为mysql语句
- 请教一个mysql的关于多表查询的问题
- 某一条记录的复制问题。
- patch for mysql.h
- 请问mySQL的mm.mysql.driver??
- you have an error in your sql syntax; check the manual that corresponds to your mysql server version
- plpgsql 中的赋值也可以用‘=’,而不用‘:=’?
create procedure jt2(title varchar(100))
begin
declare c varchar(200);
set c=concat('select id from pro where ',title);
set @a=c;
prepare stmt from @a;
execute stmt;
end//
虽然写法跟之前的不一样,但效果实现了,不过不知道为什么上面的不行。还希望有大侠帮忙解释一下。谢谢