用Python查询Oracle数据库

用Python查询Oracle数据库,python,oracle,plsql,automation,robotframework,Python,Oracle,Plsql,Automation,Robotframework,我想用python查询数据库 这是我的代码: import cx_Oracle import os def GetDatabase(queryCommand, row): conn = cx_Oracle.connect('Bell/Bell#@nn.nnn.nnn.nn:1521/Bell') cur = conn.cursor() cur.execute(queryCommand) res=cur.fetchone() i = 0 while

我想用python查询数据库

这是我的代码:

import cx_Oracle
import os

def GetDatabase(queryCommand, row):
    conn = cx_Oracle.connect('Bell/Bell#@nn.nnn.nnn.nn:1521/Bell')
    cur = conn.cursor()
    cur.execute(queryCommand)
    res=cur.fetchone()
    i = 0
    while (i < row):
        if cur.rowcount == row:
            print res
        res=cur.fetchone()
        i = i + 1
    cur.close()
    conn.close()

tup1=GetDatabase("select Name from  ContactPoint  where EmployeeID='1234'",2)
我只需要值(我不需要括号和逗号)


我尝试打印tup1[0],但它不起作用。

您应该使用
yield
而不是
print
,或者将
res
放入
列表
并返回它,因为
print
只需将它写入
sys.stdout

for row in tup1:  
    print(row[0])

您应该使用
yield
而不是
print
,或者将
res
放入
列表
并返回,因为
print
只需将其写入
sys.stdout

for row in tup1:  
    print(row[0])

我尝试在tup1:print(行[0])中查找行,但它不起作用。tup1 TypeError中的行出错:“非类型”对象不可编辑您是否已将
打印分辨率
更改为
产量分辨率
NoneType
==>
GetDatabase
return
None
,这意味着您没有按照我的建议正确执行。请仔细阅读!我尝试在tup1:print(行[0])中查找行,但它不起作用。tup1 TypeError中的行出错:“非类型”对象不可编辑您是否已将
打印分辨率
更改为
产量分辨率
NoneType
==>
GetDatabase
return
None
,这意味着您没有按照我的建议正确执行。请仔细阅读!包含实际IP地址可能不是个好主意。包含实际IP地址可能不是个好主意。