设置操作系统和oracle字符集为gbk
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
LANG=zh_CN.GBK
export LANG
数据库字符集为ZHS16GBK
脚本如下:
# -*- coding: gbk -*-
import cx_Oracle
import sys
def convert_data_to_txt(filename):
f = open(filename, 'w')
conn = cx_Oracle.connect("test/test.0.0.1/testdb")
cursor = conn.cursor()
sql = "select * from user_index"
cursor.execute(sql)
one = cursor.fetchone()
length = len(one)
row = ""
for i in range(length):
row = row + " " +str(one[i])
f.write(row + "\n")
recs = cursor.fetchall()
for rec in recs:
row = ""
for i in range(length):
row = row + " " +str(rec[i])
f.write(row + "\n")
f.close()
conn.close()
if __name__=="__main__":
filename = sys.argv[1]
convert_data_to_txt(filename)
阅读(2202) | 评论(0) | 转发(0) |