Article · 2021-10-12

Batch Administrative Code Update Script: Practical Notes

Script Generation Strategy

import csv, datetime
tpl = "update site_store set area = {new} where store_code = '{code}' and store_type = '{typ}';"
with open('mapping.csv') as f, open('update.sql','w') as out:
    for row in csv.DictReader(f):
        out.write(tpl.format(**row)+'\n')

Pre-Execution Validation

Best Execution Practices

SET SERVEROUTPUT ON
WHENEVER SQLERROR EXIT SQL.SQLCODE

Verification and Rollback

Common Pitfalls

Optimization and Extension

MERGE INTO site_store s USING tmp_area_map m
ON (s.store_code = m.store_code AND s.store_type = m.store_type)
WHEN MATCHED THEN UPDATE SET s.area = m.new_area;

Summary

© 2026 Yuxu Ge ·