您可以使用Python库 cx_Oracle 和 openpyxl 来导出Oracle数据到Excel。首先,您需要安装 cx_Oracle 库,然后连接到您的Oracle数据库,读取数据并写入Excel工作簿。代码如下:
import cx_Oracle
import openpyxl
# Connect to Oracle database
conn = cx_Oracle.connect("[user_name]/[password]@[host]:[port]/[service_name]")
cursor = conn.cursor()
# Execute query to get data
query = "SELECT * FROM [table_name]"
cursor.execute(query)
# Write data to Excel workbook
workbook = openpyxl.Workbook()
worksheet = workbook.active
# Write header row
header_row = [row[0] for row in cursor.description]
worksheet.append(header_row)
# Write data rows
for row in cursor:
worksheet.append(row)
# Save workbook
workbook.save("output.xlsx")
# Close cursor and connection
cursor.close()
conn.close()
希望这些信息能帮助到您。