我正在从Oracle源代码中读取一组字段并将检索到的数据插入到另一个Oracle Source中,当我尝试插入clob区域时,我偶然会遇到" java.sql.SQLException:ORA-00942:表或视图不存在"异常,所有字段都成功插入但clob区域。下面我将添加目标表的字段和我的示例代码。我也发现这个solution on stackoverflow并没有帮助我。目标表是oracle exadata
Table PODS.RAP_AUDIT
Column name: EVENT_ID
Column type: VARCHAR2
Column name: RUN_DATE
Column type: DATE
Column name: USER_NAME
Column type: VARCHAR2
Column name: STATUS
Column type: VARCHAR2
Column name: UNIVERSE_NAME
Column type: VARCHAR2
Column name: REPORT_NAME
Column type: VARCHAR2
Column name: CUI_ID
Column type: VARCHAR2
Column name: QUERY_NAME
Column type: VARCHAR2
Column name: REPORT_DURATION
Column type: NUMBER
Column name: ROW_COUNT
Column type: VARCHAR2
Column name: SQL
Column type: CLOB
代码:
private static void retrieveClobArea() {
String sql = "select E.START_TIME as dateval, 5087472590231472273 as idval, D.EVENT_DETAIL_VALUE as clobval from BO41AUD.ADS_EVENT_DETAIL D, BO41AUD.ADS_EVENT E where E.EVENT_ID=D.EVENT_ID and E.START_TIME >= to_date('28.07.2015 12:19:14','DD.MM.YYYY HH:MI:SS')";
try {
Class.forName(jdbcDriver);
connection = DriverManager.getConnection(sourceDBConnection,
sourceDBUser, sourceDBPass);
statement = connection.createStatement();
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
insertSampleCLOB(resultSet.getString(2), resultSet.getClob(3));
}
} catch (SQLException e) {
System.err.println(e);
} catch (ClassNotFoundException e) {
System.err.println(e);
} finally {
try {
connection.close();
} catch (SQLException e) {
System.err.println(e);
}
}
}
private synchronized static void insertSampleCLOB(String eventId, Clob sql) {
StringBuilder insertQuery = new StringBuilder();
insertQuery.append("INSERT INTO PODS.RAP_AUDIT ");
insertQuery.append("(");
insertQuery.append("EVENT_ID, ");
insertQuery.append("SQL");
insertQuery.append(") VALUES(?,?)");
try {
Class.forName(jdbcDriver);
connection = DriverManager.getConnection(targetDBConnection,
targetDBUser, targetDBPass);
preparedStatement = connection.prepareStatement(insertQuery
.toString());
preparedStatement.setString(1, eventId);
preparedStatement.setClob(2, sql);
preparedStatement.executeUpdate();
System.out.println("Inserted " + eventId + " " + new java.util.Date());
} catch (ClassNotFoundException e) {
logger.error("insertInRAP_AUDIT exception cnfe " + e);
System.err.println(e);
} catch (SQLException e) {
logger.error("insertInRAP_AUDIT exception sqle " + e);
System.err.println(e);
} finally {
try {
connection.close();
} catch (SQLException e) {
logger.error("insertInRAP_AUDIT exception connection close e "
+ e);
System.err.println(e);
}
}
}
答案 0 :(得分:-1)
在调用insertSampleClob方法之前,请执行以下操作:
Clob clob = CLOB.createTemporary(connection, false, oracle.sql.CLOB.DURATION_SESSION);
clob= resultSet.getClob(3);
然后:
insertSampleCLOB(resultSet.getString(2),clob);
它可以解决您的问题。