• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python使用cx_Oracle模块将oracle中数据导出到csv文件的方法

Python使用cx_Oracle模块将oracle中数据导出到csv文件的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python 安装cx oracle,python cx oracle,cx freeze python,cx freeze python3,cx freeze python3.5等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python使用cx_Oracle模块将oracle中数据导出到csv文件的方法。分享给大家供大家参考。具体实现方法如下:

# Export Oracle database tables to CSV files
# FB36 - 201007117
import sys
import csv
import cx_Oracle
connection = raw_input("Enter Oracle DB connection (uid/pwd@database) : ")
orcl = cx_Oracle.connect(connection)
curs = orcl.cursor()
printHeader = True # include column headers in each table output
sql = "select * from tab" # get a list of all tables
curs.execute(sql)
for row_data in curs:
  if not row_data[0].startswith('BIN$'): # skip recycle bin tables
    tableName = row_data[0]
    # output each table content to a separate CSV file
    csv_file_dest = tableName + ".csv"
    outputFile = open(csv_file_dest,'w') # 'wb'
    output = csv.writer(outputFile, dialect='excel')
    sql = "select * from " + tableName
    curs2 = orcl.cursor()
    curs2.execute(sql)
    if printHeader: # add column headers if requested
      cols = []
      for col in curs2.description:
        cols.append(col[0])
      output.writerow(cols)
    for row_data in curs2: # add table rows
      output.writerow(row_data)
    outputFile.close()
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • python安装cx_Oracle模块常见问题与解决方法
  • python cx_Oracle模块的安装和使用详细介绍
  • Python使用cx_Oracle模块将oracle中数据导出到csv文件的方法

相关文章

  • 详解Python中表达式i += x与i = i + x是否等价
  • Windows中安装使用Virtualenv来创建独立Python环境
  • python中threading超线程用法实例分析
  • 使用Python保存网页上的图片或者保存页面为截图
  • python获取本机mac地址和ip地址的方法
  • python实现查询IP地址所在地
  • ssh批量登录并执行命令的python实现代码
  • Python写的贪吃蛇游戏例子
  • python 捕获 shell/bash 脚本的输出结果实例
  • Python使用函数默认值实现函数静态变量的方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python3使用requests包抓取并保存网页源码的方法
    • 用ReactJS和Python的Flask框架编写留言板的代码示例
    • Python标准库06之子进程 (subprocess包) 详解
    • 解析Python中while true的使用
    • Python中for循环和while循环的基本使用方法
    • Python中使用urllib2防止302跳转的代码例子
    • python实现实时监控文件的方法
    • python 控制语句
    • 使用相同的Apache实例来运行Django和Media文件
    • Python的Flask框架中实现简单的登录功能的教程

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有