#python操作Oracle依赖cx_Oracle
#pip install cx_Oracle
#pip install pandas
import os
from pandas.core.frame import DataFrame
import cx_Oracle
import pandas as pd
def query(ip,port,sid,username,password,sql):
dsn = cx_Oracle.makedsn(ip, port, sid)
conn = cx_Oracle.connect(username, password, dsn)
results = pd.read_sql(sql,conn)
conn.close
return results
def writeQueryToTxt(results:DataFrame,filedir):
results.to_csv(filedir,sep=‘\001‘,index=False,header=False)
if __name__ == "__main__":
sql = "select * from test"
df = query("127.0.0.1","1521","xe","ods","ods",sql)
df[‘BIRTH‘] = df[‘BIRTH‘].apply(lambda x:x.strftime(‘%Y-%m-%d‘))
writeQueryToTxt(df,"./test.txt")