关于cx oracle:如何在Python中以逗号分隔的字符串变量提取SQL的查询结果

How to extract query results of an SQL in a comma delimited string variable in Python

我必须在python中将Oracle表中的查询结果提取为逗号分隔的字符串。

谢谢,


下面的代码可以工作,更多细节请参考如何将二维列表展平为1d。

1
2
3
4
5
6
7
8
9
10
11
"""
conn = ora.connect("HR","oracle","localhost/xe")
cur=conn.cursor()
cur.execute('select * from employees')
dataset = cur.fetchall()
"""
dataset = [['1','FirstName1', 'LastName1', 'Department1'],
           ['2','FirstName2', 'LastName2', 'Department2']]
s = ','.join([item for row in dataset for item in row] )
print s
#output: 1,FirstName1,LastName1,Department1,2,FirstName2,LastName2,Department2