Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2139822
  • 博文数量: 157
  • 博客积分: 10047
  • 博客等级: 上将
  • 技术积分: 6757
  • 用 户 组: 普通用户
  • 注册时间: 2005-05-19 11:38
文章分类

全部博文(157)

文章存档

2011年(16)

2010年(50)

2009年(42)

2008年(49)

我的朋友

分类:

2011-06-21 16:54:28

设置操作系统和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)
阅读(2160) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~