在Oracle中,要批量更新多條數據可以使用以下方法之一:
MERGE INTO table_name dest
USING (SELECT id, new_value FROM updated_data) src
ON (dest.id = src.id)
WHEN MATCHED THEN UPDATE SET dest.column_name = src.new_value;
DECLARE
TYPE id_table IS TABLE OF table_name.id%TYPE INDEX BY PLS_INTEGER;
TYPE value_table IS TABLE OF table_name.column_name%TYPE INDEX BY PLS_INTEGER;
ids id_table;
values value_table;
BEGIN
-- 填充ids和values數組
FOR i IN 1..ids.COUNT LOOP
UPDATE table_name
SET column_name = values(i)
WHERE id = ids(i);
END LOOP;
END;
使用以上兩種方法可以實現在Oracle數據庫中批量更新多條數據。