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]