I am running ArcGIS 10.0 desktop and querying an Oracle 11g database and writing the results of a SELECT statement out to a CSV file. Everything works great; however, I would love to find a way to include the column names in the CSV without hard coding them.
My code looks like this:
obj_sde_conn_ora = arcpyArcSDESQLExecute(server, port, "#", user, password)
sql_ora_select = """SELECT col1, col2
FROM tab"""
sde_return = obj_sde_conn_ora.execute(sql_ora_select)
csv_file = open(out_csv, "wb")
import csv
csv_writer = csv.writer(csv_file, delimiter=";", quotechar='"', quoting=csv.QUOTE_MINIMAL)
for row in sde_return:
csv_writer.writerow([unicode(s).encode("utf8", "replace") for s in row])
del sde_return
csv_file.close()