如何使用jdbc oracle插入和选择全局临时表?

时间:2018-09-18 12:10:21

标签: java oracle

 String query = "INSERT INTO St (id) values ('Admin'); "  + 
            "select * from Student where id in (select id from St);";

尝试执行上述查询时出错

Exception in thread "main" java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:446)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1054)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:623)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:612)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:226)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:59)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:910)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1119)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3780)
at oracle.jdbc.driver.T4CPreparedStatement.executeInternal(T4CPreparedStatement.java:1343)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3822)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1165)
at com.prototype.service.DBConnection.main(DBConnection.java:167)
  

原因:错误:933,位置:36,Sql =插入到St(id)中   值(“管理员”);从学生所在的ID中选择*   St);, OriginalSql = INSERT INTO St(id)值('Admin');选择 *   来自学生所在的ID(从St中选择ID);错误消息= ORA-00933:   SQL命令未正确结束

1 个答案:

答案 0 :(得分:0)

您可以使用插入选择语句,这样可以避免多状态查询

String query = "INSERT INTO St (id) 
            select your_col_for_id  from Student where id in (select id from St);";

并且必须确保in子句和select子句

中具有相应的列数和类型