我的問題是:如何在CLOB
插入(或在查詢中執行任何操作)時遇到ORA-01704: string literal too long
錯誤?將CLOB插入到Oracle數據庫中
我想有這樣的查詢:
INSERT ALL
INTO mytable VALUES ('clob1')
INTO mytable VALUES ('clob2') --some of these clobs are more than 4000 characters...
INTO mytable VALUES ('clob3')
SELECT * FROM dual;
當我嘗試將其與實際值雖然我得到ORA-01704: string literal too long
回來。這是非常明顯的,但我如何插入clobs(或用clob執行任何語句)?
我試過看這question,但我不認爲它有我在找什麼。我有的clobs在List<String>
,我遍歷他們做出聲明。因爲這是我的代碼如下:
private void insertQueries(String tempTableName) throws FileNotFoundException, DataException, SQLException, IOException {
String preQuery = " into " + tempTableName + " values ('";
String postQuery = "')" + StringHelper.newline;
StringBuilder inserts = new StringBuilder("insert all" + StringHelper.newline);
List<String> readQueries = getDomoQueries();
for (String query : readQueries) {
inserts.append(preQuery).append(query).append(postQuery);
}
inserts.append("select * from dual;");
DatabaseController.getInstance().executeQuery(databaseConnectionURL, inserts.toString());
}
public ResultSet executeQuery(String connection, String query) throws DataException, SQLException {
Connection conn = ConnectionPool.getInstance().get(connection);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
conn.commit();
ConnectionPool.getInstance().release(conn);
return rs;
}
而是動態SQL和建設有字符串文字的INSERT語句,你嘗試使用'PreparedStatement'和它的'setClob()'方法? – QuantumMechanic