如果傳入的參數值爲空,如何創建不更新列的批量更新?例如:在Java中執行SQL批量更新時,如果傳入參數parm不會更新字段
String UPDATE_STMT = "UPDATE MY_TABLE SET col1 = ?, col2 = ?, col3 = ?";
Connection conn = getConnection();
PreparedStatement pstmt = conn.preparedStatement(UPDATE_STMT);
List items = getItems();
for (ItemType item : items) {
stmt.setString(1, item.x);
stmt.setString(2, item.y);
stmt.setString(3, item.z);
}
pstmt.executeBatch();
如何編碼它,以便col1只會更新item.x的值,如果item.x不爲null或爲空?如果item.x爲空/空,我不希望col1字段中的當前值被覆蓋。這是針對Oracle 10g數據庫的。
這樣做,即使col1爲空? – wlaem
如果參數全爲空,則COALESCE返回null。 – Jim