2013-01-11 118 views
0

在等同于cx_Oracle.executemany,我可以用来排除?用executemany删除cx_oracle?

用一个非常简单的例子即时通讯使用这块代码插入数据,但它可能做到删除条目?

try: 

    con = None 

    con = cx_Oracle.connect(uid , pwd, dsn) 
    cur = con.cursor() 
    cur.executemany(sql,params) 
    con.commit() 

except cx_Oracle.DatabaseError, e: 

     print 'Error %s' % e 
     sys.exit(1) 

finally: 

    if con: 

     con.close() 

回答

1

DB-API支持使用executemany()删除多行。我没有Oracle数据库方便,但下面是使用SQLite的测试示例:

import sqlite3 
conn = sqlite3.connect(':memory:') 
conn.execute('create table t (c);') 
conn.executemany("insert into t values (?);", ('a','b','c',)) 
conn.execute('select c from t;').fetchall() 
# -> [(u'a',), (u'b',), (u'c',)] 
conn.executemany('delete from t where c = ?;', ('a','b',)) 
conn.execute('select c from t;').fetchall() 
# -> [(u'c',)] 
conn.close() 
+0

谢谢你指出。 –

+0

非常欢迎。快乐的编码。 – bernie