Mybatis 查询Cause: java.sql.SQLSyntaxErrorException: ORA-00903: 表名无效

起因想通过通用方法加载不同表名查询数据,使用Mybatis查询报错

 @Select(" select   #{column}  as str  from  #{table}  group by  #{column} order by count(1) desc ")

在这里插入图片描述

#{table} 修改为 ${table} 查询数据

 @Select(" select   #{column}  as str  from  ${table}  group by  #{column} order by count(1) desc")

执行查询返回结果只有列名,但没有数据在这里插入图片描述

需要将查询修改为

@Select(" select   ${column}  as str  from  ${table}  group by  ${column} order by count(1) desc")
查询结果正确

在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐