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