python对Oracle数据库接口cx_Oracle
程序员文章站
2023-11-13 09:26:52
python对Oracle数据库的操作用cx_Oracle库操作简单,例如#例子import cx_Oraclecon = cx_Oracle.connect("pythondemo/welcome@192.168.188.11:1521/std1")cur = con.cursor()rows =... ......
python对oracle数据库的操作用cx_oracle库
操作简单,例如
#例子
import cx_oracle
con = cx_oracle.connect("pythondemo/welcome@192.168.188.11:1521/std1")
cur = con.cursor()
rows = [ (1, "first" ), (2, "second" ),
(3, "third" ), (4, "fourth" ),
(5, "fifth" ), (6, "sixth" ),
(7, "seventh" ) ]
cur.execute("truncate table mytab")
cur.executemany("insert into mytab(id, data) values (:1, :2)", rows)
con.commit()
cur.execute('select * from mytab')
res = cur.fetchall()
print(res)
cur.close()
con.close()
例2
import pandas as pd
import cx_oracle
con = cx_oracle.connect("scott","tiger","192.0.2.21:1521/std1")
d = pd.read_sql('select * from emp',con)