简体   繁体   中英

Get column value by name rather than position in cx_Oracle

Using cx_Oracle , I am selecting data from an Oracle database.

curs = cxn.cursor()
result = curs.execute(SELECT FirstName, LastName FROM Person)

Is there a way to return only the firstname without numerical index? For example:

for row in result:
    result[0] #will return the first column

What I am hoping to do is call the value like result['FirstName']

Using cx_Oracle , I am selecting data from an Oracle database.

curs = cxn.cursor()
result = curs.execute(SELECT FirstName, LastName FROM Person)

Is there a way to return only the firstname without numerical index? For example:

for row in result:
    result[0] #will return the first column

What I am hoping to do is call the value like result['FirstName']

Using cx_Oracle , I am selecting data from an Oracle database.

curs = cxn.cursor()
result = curs.execute(SELECT FirstName, LastName FROM Person)

Is there a way to return only the firstname without numerical index? For example:

for row in result:
    result[0] #will return the first column

What I am hoping to do is call the value like result['FirstName']

nmcol=[row[0] for row in c.description]
# print(nmcol)
for row in cursor:
  print(row[nmcol.index('FirstName')])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM