zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Flask之threading.loacl方法
    websocket之简易聊天室
    websocket介绍
    Flask之jinja2模板语言
    Flask之基础
    Linux之项目的部署
    Linux之nginx负载均衡
    Linux之nginx
    Linux之redis-cluster
    Linux之redis-sentinel
  • 原文地址:https://www.cnblogs.com/sxbjdl/p/5842753.html
Copyright © 2011-2022 走看看