python操作oracle数据库
时间:2021-07-01 10:21:17
帮助过:21人阅读
#encoding=utf-8
2
3 import cx_Oracle
4 import sys
5 reload(sys)
6 sys.setdefaultencoding(
‘utf-8‘)
7
8 #参数为:用户名、密码、TSN
9 tns=cx_Oracle.makedsn(
‘127.0.0.1‘,1521,
‘orcl‘)
10 conn = cx_Oracle.connect(
‘system‘,
‘sasa‘,tns)
11
12 #创建cursor
13 cursor =
conn.cursor()
14
15 sql =
"select table_name from user_tables "
16
17 #执行sql语句
18 cursor.execute(sql)
19
20
21 #获取所有的记录
22 one =
cursor.fetchall()
23
24
25 #一条一条的访问记录
26 for x
in one:
27 print x
28
29 #关闭cursor
30 cursor.close()
31
32 #关闭连接
33 conn.close()
34
35 print(u
‘OK‘)
python操作oracle数据库
标签:log sys blog 11g 执行 style 获取 odi nec