-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpJ.py
32 lines (24 loc) · 1.08 KB
/
expJ.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import oracledb as oraDB
import json
from datetime import datetime
import pandas
# Resto del tuo codice...
def output_type_handler(cursor, name, default_type, size, precision, scale):
if default_type == oraDB.DB_TYPE_CLOB:
return cursor.var(oraDB.DB_TYPE_LONG, arraysize=cursor.arraysize)
if default_type == oraDB.DB_TYPE_BLOB:
return cursor.var(oraDB.DB_TYPE_LONG_RAW, arraysize=cursor.arraysize)
# Eseguire una query di esempio
def tableExportJson (table, conn):
conn.outputtypehandler = output_type_handler
cursor = conn.cursor()
query = f"SELECT * FROM {table}"
cursor.execute(query)
lobResults=cursor.fetchall()
# Get column names from the cursor description
columns = [col[0] for col in cursor.description]
# Create a DataFrame using the fetched results and column names
results = pandas.DataFrame(lobResults, columns=columns)
data = datetime.now().strftime("%Y%m%d")
resultsJSON = results.to_json (f'JSON\{data}_{table}.json',orient="records",indent=True)
print (f'creato file: JSON\{data}_{table}.json')