您的位置:首页 > 数据库 > Oracle

使用python访问Oracle数据库

2010-11-30 00:09 531 查看
import cx_Oracle
import os

if False:  #当Oracle服务是手动运行时,将False改为True
os.system('net start OracleVssWriterORCL')
os.system('net start OracleDBConsoleorcl')
os.system('net start OracleOraDb11g_home1TNSListener')
os.system('net start OracleServiceORCL')

orcl = cx_Oracle.connect('system/username@localhost:1521/orcl'.decode('utf8'))
cur = orcl.cursor()

sql = '''select * from test1
'''
cur.execute(sql.decode('utf8'))
records = cur.fetchall()
lines = len(records)
for i in range(lines):
print records[i]
cur.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: