1. 程式人生 > >; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00907: 缺失右括號

; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00907: 缺失右括號

SELECT P.*, ROWNUM AS rowno FROM
 (SELECT * FROM "equipment_info","equipment_status","user","parking_lot"
 WHERE "equipment_info"."parking_id"="parking_lot"."id"
 and "equipment_info"."status"="equipment_status"."id"
 and "equipment_info"."principal_id"="user"."id") P
 WHERE ROWNUM < #{nextOffset,jdbcType=INTEGER}) T
 WHERE T.rowno >= #{pageOffset,jdbcType=INTEGER}

聯表查詢所有記錄和equipment_info的記錄條數

得到缺失右括號的問題

檢查語法什麼都沒有問題

猜測可能是因為這種聯表查詢查記錄個數有問題

改為左聯表

SELECT P.*, ROWNUM AS rowno FROM
(SELECT * FROM "equipment_info" left join "parking_lot" on "equipment_info"."parking_id"="parking_lot"."id"
 left join "equipment_status" on "equipment_info"."status"="equipment_status"."id"
 left join "user" on "equipment_info"."principal_id"="user"."id") P
 WHERE ROWNUM < #{nextOffset,jdbcType=INTEGER}) T
 WHERE T.rowno >= #{pageOffset,jdbcType=INTEGER}

解決了問題