PythonからOracleに接続し、データを登録&更新する
昨日の続き。
INSERTは複数行の登録が一度にできるけど、UPDATEは複数回execute呼ばないといけないらしい。
# Insert default rows rows = [(1, 'Bob', 35, 'I like dogs'), (2, 'Kim', 27, 'I like birds')] cur.bindarraysize = 2 cur.setinputsizes(int, 20, int, 100) cur.executemany("insert into cx_people(id, name, age, notes) values (:1, :2, :3, :4)", rows) con.commit() #Update cur = con.cursor() statement = 'update cx_pets set owner = :1 where owner = :2 and type = :3' cur.execute(statement, (2, 1, 'dog')) con.commit()