Why the need to commit explicitly when doing an UPDATE?

前端 未结 3 2175
迷失自我
迷失自我 2020-12-03 21:50

Here\'s my code:

import cx_Oracle

conn = cx_Oracle.connect(usr, pwd, url)
cursor = conn.cursor()
cursor.execute(\"UPDATE SO SET STATUS=\'PE\' WHERE ID=\'100         


        
3条回答
  •  臣服心动
    2020-12-03 22:17

    Others have explained why a commit is not necessary on a SELECT statement. I just wanted to point out you could utilize the autocommit property of the Connection object to avoid having to manually execute commit yourself:

    import cx_Oracle
    
    with cx_Oracle.connect(usr, pwd, url) as conn:
        conn.autocommit = True
        cursor = conn.cursor()
        cursor.execute("UPDATE SO SET STATUS='PE' WHERE ID='100'")
        cursor.close()
    

    This is especially useful when you have multiple INSERT, UPDATE, and DELETE statements within the same connection.

提交回复
热议问题