python 将sql语句批量导出excel

import sys
import cx_Oracle
import psycopg2
import xlrd
import xlwt
import pandas as pd
import datetime
import get_all_list_settings as st  #在这里定义字典sql,或者改下面参数sqldict



#sqldict = {"t_风险1":" select * from t1 ",
#           "t_风险2":" select * from t1 "}


def fn_get_data_fromDB(st):
    Ocon = cx_Oracle.connect('clound_op', 'clound_op', '192.168.1.103:1521/yydb')
    Ocursor = Ocon.cursor()
    for stName  in st.sqldict:
        print(stName )
        sql_stName = st.sqldict[stName]
        data = pd.read_sql_query(sql_stName, Ocon)
        data.to_excel(stName+'.xlsx')

if __name__ == '__main__':
    fn_get_data_fromDB(st)



 

你可能感兴趣的:(python 将sql语句批量导出excel)