• python连接oracle数据库


    python连接oracle通过cx-oracle包

    安装cx_oracle:pip install cx_oracle

    在执行这步时遇到个坑,找不到vc编译器

    其实很简单,访问这个网址 http://www.microsoft.com/en-us/download/details.aspx?id=44266,下载安装一下就ok了

    安装完毕后 import cx_oracle出错了,这个坑是自己抛的

    o要大写!!要大写!!

    import cx_Oracle

    使用sqlalchemy

    from sqlalchemy import *  
    from sqlalchemy.sql import select  
    from sqlalchemy.schema import *  
    import numpy as np
    import pandas as pd
    import os
    
    # create the engine for oracle db  
    # we need to install cx_Oracle and sqlalchemy in advance.  
    db_engine=create_engine('oracle://vehicle:VEHICLE@10.10.11.171:1521/orcl', echo=True)  
    conn=db_engine.connect() 
    
    query=pd.read_sql_query("select * from HIS_LITHIUM_CAN_DATA@orcl195",conn,chunksize=1000)
    
    def ToDisk(filename):
        first=query.next()
        first.to_csv(filename,encoding="utf-8")
        for line in query:
            line.to_csv(filename,header=False,mode="a+",encoding="utf-8")
    
    os.chdir('E:/work/data')
    ToDisk('HIS_LITHIUM_CAN_DATA.csv')

    参考资料

    http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/0014021031294178f993c85204e4d1b81ab032070641ce5000

  • 相关阅读:
    POJ 1321 棋盘问题
    算法导论 4.1 最大子数组问题
    矩阵快速幂
    固定定位
    HTML排版
    CSS笔记2
    HDU 1796 How many integers can you find(容斥原理)
    HDU 2147 kiki's game(博弈经典题)
    HDU 1846 Brave Game(巴什博弈超简单题)
    HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
  • 原文地址:https://www.cnblogs.com/sxbjdl/p/5842753.html
Copyright © 2020-2023  润新知