用python连接oracle
时间:2009-06-15 来源:蔡强
简单写了一个小脚本
import os
import sys
import cx_Oracle
from pprint import pprint
answer = raw_input("请启动oracle服务:Y/N?:" )
if (answer == 'N' or answer == 'n'):
shili = raw_input("请输入你要启动的数据库实例:")
print "oracleservice%s 服务正在启动..." % (shili)
start = 'net start oracleservice%s' % (shili)
os.system(start)
print "服务启动成功"
else:
print "服务已经启动"
answer_1 = raw_input("请启动oracle监听程序?Y/N?:")
if (answer_1 == 'N' or answer_1 == 'n'):
start_1 = 'lsnrctl start'
start_2 = 'lsnrctl status'
os.system(start_1)
os.system(start_2)
print "正在监听"
else:
print "服务已经启动"
#登录scott用户,做简单查询
db = cx_Oracle.connect('scott/oracle')
cursor = db.cursor()
cursor.execute('select * from emp')
pprint(cursor.fetchall())
import os
import sys
import cx_Oracle
from pprint import pprint
answer = raw_input("请启动oracle服务:Y/N?:" )
if (answer == 'N' or answer == 'n'):
shili = raw_input("请输入你要启动的数据库实例:")
print "oracleservice%s 服务正在启动..." % (shili)
start = 'net start oracleservice%s' % (shili)
os.system(start)
print "服务启动成功"
else:
print "服务已经启动"
answer_1 = raw_input("请启动oracle监听程序?Y/N?:")
if (answer_1 == 'N' or answer_1 == 'n'):
start_1 = 'lsnrctl start'
start_2 = 'lsnrctl status'
os.system(start_1)
os.system(start_2)
print "正在监听"
else:
print "服务已经启动"
#登录scott用户,做简单查询
db = cx_Oracle.connect('scott/oracle')
cursor = db.cursor()
cursor.execute('select * from emp')
pprint(cursor.fetchall())
相关阅读 更多 +