LoginSignup
0
0

More than 1 year has passed since last update.

pythonでoracle-dbにつなぐ

Posted at

インストール

pip install cx_Oracle

エラーが出たとき

error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

下記記事で解決

★★「MSVC v140」にチェックを入れるのがポイントかな

selectの例

import cx_Oracle
tns = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.1)(PORT=1521)))(CONNECT_DATA=(SID=orcl)(SERVER=DEDICATED)))"
conn = cx_Oracle.connect('id', 'pass', tns)
cur = conn.cursor()
cur.execute("select * from table1 where id like 'hoge%'")
res = cur.fetchall()
print(res)
cur.close()
conn.close()

updateの例

import cx_Oracle
tns = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.1)(PORT=1521)))(CONNECT_DATA=(SID=orcl)(SERVER=DEDICATED)))"
conn = cx_Oracle.connect('id', 'pass', tns)
cur = conn.cursor()
cur.execute("update table1 set field2=0 where id like 'hoge%'")
conn.commit()
cur.close()
conn.close()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0