Windows7でPython3.5環境で cx_Oracleを使う

pythonでOracleへ接続したい。

[python]
import cx_Oracle
import os
os.environ["NLS_LANG"] = "Japanese_Japan.AL32UTF8"

tns = cx_Oracle.makedsn("192.168.0.1",1521,"ORASID")
connection = cx_Oracle.connect("user","pass",tns)
#connection = cx_Oracle.connect("user","pass","(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.1) (PORT=1521))(CONNECT_DATA=(SID=ORASID)))")

cursor = connection.cursor()
agent_cd = ‘7’
sql = """
select agent_cd, agent_name
from agents
where agent_cd = :agent_cd
"""
cursor.execute(sql, agent_cd)
rows = cursor.fetchall()
for agent in rows:
print(agent[0], agent[1])

[/python]

This entry was posted in Python, 技術情報. Bookmark the permalink.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です