I am trying to export csv from Oracle DB using python(pandas). But the first csv file only has been exported correctly. The other csv files have been exported uncorrectly(just 1KB). I guess rownum problem. Could anyone tell me how to solve this problem?
import cx_Oracle
import pandas as pd
import os
connect=cx_Oracle.connect('PIAS', 'tkeodus2021', 'localhost:1539/Oracle8')
cursor=connect.cursor()
row_length_list=[9520691, 2929400, 48641]
sql_list = [
"""SELECT title, main FROM TMP_PTTN_2020""",
"""SELECT title, main FROM TMP_SAEOL_2020""",
"""SELECT title, main FROM TMP_DFPT_2020"""
]
filename_list = [
"D:\PTTN_2020.csv",
"D:\SAEOL_2020.csv",
"D:\DFPT_2020.csv"
]
split = 10
for i in range(len(sql_list)):
row_length = row_length_list[i]
div = int(row_length/split) + 1
for j in range(split):
start = j * div
end = (j + 1) * div
sql = sql_list[i] + " WHERE ROWNUM >=" + str(start) + " AND ROWNUM < " + str(end)
print(sql)
df = pd.read_sql(sql, con=connect)
df.to_csv(filename_list[i].split('.')[0] + "_" + str(j) + ".csv", index=False)