<select id="getBindPhoto" resultType="vip.xiaonuo.modular.zpdy.param.CarPhotosParam">…
- User
运行报错 SQL: select * form (select t.*,rownum rn from car_photos t,car_photos_log f where t.photo_refresh_gid = f.photo_refresh_gid and t.xh=? and f.czlx='1' order by t.last_timestamp desc ) where a.rn between 0 and ?
Cause: java.sql.SQLSyntaxErrorException: ORA-00923: 未找到要求的 FROM 关键字
- Assistant
根据您提供的SQL语句以及错误信息,错误是由于一个语法问题。具体来说,“form”应该是“from”。这是一个常见的拼写错误。以下是修正后的SQL语句:
<select id="getBindPhoto" resultType="vip.xiaonuo.modular.zpdy.param.CarPhotosParam"> select * from ( select t.*, rownum rn from car_photos t, car_photos_log f where t.photo_refresh_gid = f.photo_refresh_gid and t.xh = #{xh} and f.czlx = '1' order by t.last_timestamp desc ) where rn between 0 and #{maxRetrun} </select>以下是对代码的重要修正点和一些优化建议:
-
拼写错误: 将“form”更正为“from”。
-
别名使用: 在外层
where子句中,rn不需要别名a.。 -
索引起始值:
rownum从1开始,一般来说,between 0 and ...可能需要调整为between 1 and ...。
这些修改应能解决您遇到的语法错误。建议在调整后再次运行查询以确认是否解决问题。
-
- User
select * from (select t.*,rownum rn from car_photos t,car_photos_log f where t.photo_refresh_gid = f.photo_refresh_gid and t.xh=? and f.czlx='1' order by t.last_timestamp desc ) where a.rn between 0 and ?
Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "A"."RN": 标识符无效
修正from后 又报错
- Assistant
根据您描述的错误信息,“ORA-00904: 标识符无效”通常指的是SQL中的列名或别名无效。在您的SQL中,别名
a没有定义,所以它在where子句中会导致无效标识符错误。以下是修正后的SQL语句:select * from ( select t.*, rownum rn from car_photos t, car_photos_log f where t.photo_refresh_gid = f.photo_refresh_gid and t.xh = ? and f.czlx = '1' order by t.last_timestamp desc ) where rn between 1 and ?以下是修正和建议的说明:
-
别名问题: 原始SQL在外层
where条件中使用了a.rn,但并未在查询中为整个子查询指定别名。直接使用rn即可,而无需使用任何别名。 -
rownum使用:rownum从1开始,所以between 0 and ?可能需要调整为between 1 and ?。这样能确保获取有效的行。 -
参数占位符: 请确保在实际运行中用合适的参数替换占位符“?”和“#{maxRetrun}”。
确保在应用代码中正确设置参数绑定并对应到 SQL 中的占位符,以避免运行时错误。希望这些修改可以解决问题。
-