python链接Oracle数据库的方法

yipeiwu_com6年前Python基础

本文实例讲述了python链接Oracle数据库的方法。分享给大家供大家参考。具体如下:

这里使用python链接Oracle数据库需要引用cx_Oracle库

#coding=UTF-8
  import cx_Oracle
  def hello():
    '''Hello cx_Oracle示例:
    1)打印数据库版本信息.
    2)查询表数据.'''
    conn = cx_Oracle.connect("obs61","obs61","tx8i.hp")
    cur = conn.cursor()
    try:
      print "Oracle Version:%s" % conn.version
      print "Table SUB_POLICY rows:"
      cur.execute('select * from wlan_future_event')
      for row in cur:
        print row
    finally:
      cur.close()
      conn.close()
  hello()

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

相关文章

Python3实现Web网页图片下载

先来介绍一些python web编程基础知识 1. GET与POST区别 1)POST是被设计用来向web服务器上放东西的,而GET是被设计用来从服务器取东西的,GET也能够向服务器传送...

python3 动态模块导入与全局变量使用实例

动态导入有两种: 1 __main__(): f="demo.A" aa=__main__(f) aa.A.t() 2 import importlib: import...

Python实现的Excel文件读写类

本文实例讲述了Python实现的Excel文件读写类。分享给大家供大家参考。具体如下: #coding=utf-8 #################################...

Python编程实现输入某年某月某日计算出这一天是该年第几天的方法

本文实例讲述了Python编程实现输入某年某月某日计算出这一天是该年第几天的方法。分享给大家供大家参考,具体如下: #基于 Python3 一种做法: def is_lea...

mac下如何将python2.7改为python3

mac下如何将python2.7改为python3

1.查看当前电脑python版本 python -V  // 显示2.7.x 2.用brew升级python brew update python  3.如果安装...