写了一个存储过程:
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不知道这样的效果应该怎么实现,哪个大侠帮忙指导一下,谢谢!
解决方案 »
- 如何用sql删除冗余整行都有冗余的记录(全部字段)
- Mysql里怎么获取某一项有哪些值 相当于将值放到map里
- sqlserver迁移到postgreSQL
- 数据表拆分后查询问题
- mysql中为什么不能使用top *类似这种的大范围的查询?
- 请教高手:怎末样将 DATA insert into ( 存入MYSQL )database?
- 非常紧急,在线等待,来者有分!
- 一个树型结构数据如何储存到关系型数据库中?
- 求大神给个大流量数据库的优化建议
- sysbench压测mycat报错
- 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//
虽然写法跟之前的不一样,但效果实现了,不过不知道为什么上面的不行。还希望有大侠帮忙解释一下。谢谢