import cx_Oracle
,time
,os
,sys
def get_data_from_oracle():
db
= cx_Oracle
.connect
('user', 'pwd', '10.3.1.100:1521/xx')
cursor
= db
.cursor
()
sql
= "select * from order_table"
print (sql
+ "\n")
cursor
.execute
(sql
)
result
= cursor
.fetchall
()
cursor
.close
()
db
.close
return result
argv
= sys
.argv
gdate
= argv
[1]
ghour
= argv
[2]
TMPDIR
="/opt/ourpalm/scripts/tmp"
retFile
=TMPDIR
+ "/flume." + ghour
+ "." + str(int(time
.time
())) + "." + gdate
+ ghour
+ ".log"
print("retFile = " + retFile
+ "\n")
result
= get_data_from_oracle
()
file = open(retFile
, 'w')
for row
in result
:
field
= ""
for f
in row
:
if None == f
:
field
+= "|"
else:
if isinstance(f
, float):
field
+= '{:.10g}'.format(f
) + "|"
else:
field
+= str(f
) + "|"
field
= field
[:-1]
file.write
(field
+ "\n")
file.close
()
os
.remove
(retFile
)
sys
.exit
()
转载请注明原文地址:https://tech.qufami.com/read-13099.html