python将oracle数据库保存到excel


上代码:

import pandas  as pd
import SqlHelper.ORACLE as ORA

if __name__ == '__main__': 
    #连接数据库
    ms = ORA.ORACLE(host="localhost:1521",db="orcl",user="example",pwd="example")

    ########################################################## 方式一:先读取为二维list,再转dataframe,最后保存为Excel
    reslist = ms.ExecQuery("select * from version ")
    # list转dataframe
    df1 = pd.DataFrame(reslist, columns=['ID', 'VERSION', 'MESSAGE'])
    df1.to_excel("E:\\MyPrj\\Python\\Files\\Excel1.xlsx", index=False)

    ########################################################## 方式二:直接读取为dataframe,然后保存为Excel
    df2 = ms.ExecQueryToDataFrame("select * from version ")
    df2.to_excel("E:\\MyPrj\\Python\\Files\\Excel2.xlsx", index=False)

 

如果对您有帮助,请赞助根棒棒糖~


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM