我试图通过JDBC在Oracle DB中执行以下查询,但它抛出异常。例外是:
java.sql.SQLException: ORA-00933: SQL command not properly ended
请建议需要更改的内容?
String questionQuery = "SELECT PCN_SURVEY_DEFINITION.ID, PCN_SURVEY_DEFINITION.NAME, PCN_QUESTIONS.ID, PCN_QUESTIONS.SURVEY_ID, PCN_QUESTIONS.LABEL, "
+ "PCN_QUESTIONS.TYPE, PCN_QUESTIONS.REQUIRED, PCN_QUESTIONS.COMMENTS, PCN_QUESTIONS.DISPLAY_ORDER "
+ "FROM PCN_SURVEY_DEFINITION, PCN_QUESTIONS "
+ "WHERE PCN_SURVEY_DEFINITION.ID = PCN_QUESTIONS.SURVEY_ID "
+ "AND PCN_SURVEY_DEFINITION.NAME=? "
+ "ORDER BY PCN_QUESTIONS.DISPLAY_ORDER ASC";
答案 0 :(得分:1)
What do you do with the question mark? Maybe you meant to put a column name here of the other table? The one before the ORDER BY? Or are you using a prepared statement afterwards? Try removing this condition temporarily for testing purposes: "AND PCN_SURVEY_DEFINITION.NAME=? "
"WHERE PCN_SURVEY_DEFINITION.ID = PCN_QUESTIONS.SURVEY_ID " + "AND PCN_SURVEY_DEFINITION.NAME=? " + "ORDER BY
答案 1 :(得分:1)
更正WHERE子句中的条件并正确检查引号(“)从哪里开始以及在哪里结束。
"WHERE PCN_SURVEY_DEFINITION.ID = " + PCN_QUESTIONS.SURVEY_ID + " AND PCN_SURVEY_DEFINITION.NAME=? " + "ORDER BY PCN_QUESTIONS.DISPLAY_ORDER ASC";
答案 2 :(得分:1)
Oracle不支持问号"?"。对于变量绑定oracle使用":name"或":1"
https://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci05bnd.htm
答案 3 :(得分:0)
我有类似的东西,不得不在我的application.properties
文件中添加以下属性(因为我使用的是Spring Boot),这解决了我的问题而无需更改任何SQL
spring.jpa.database=oracle