Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python cx_oracle cursor.rowcount返回0,但cursor.fetchall返回数据_Python_Sql_Database_Oracle11g_Cx Oracle - Fatal编程技术网

python cx_oracle cursor.rowcount返回0,但cursor.fetchall返回数据

python cx_oracle cursor.rowcount返回0,但cursor.fetchall返回数据,python,sql,database,oracle11g,cx-oracle,Python,Sql,Database,Oracle11g,Cx Oracle,我使用cx\U oracle包执行python代码中的select sql语句的代码如下: import cx_Oracle try: cur = conn.cursor() result = cur.execute('select * from table1') print(str(cur.rowcount)) print(cur.fetchall()) except Exception as e: print(e) 当我执行上述代码时,我看到0为

我使用
cx\U oracle
包执行
python
代码中的
select sql
语句的代码如下:

import cx_Oracle

try:
    cur = conn.cursor()
    result = cur.execute('select * from table1')
    print(str(cur.rowcount))
    print(cur.fetchall())

except Exception as e:
    print(e)
当我执行上述代码时,我看到
0
cur.rowcount
输入,但我看到为
cur.fetchall()打印以下数据:

是否提到
游标。行计数
是一个有效的操作,因此我不确定为什么在我的代码中,即使数据即将到来,它仍返回
0

提到游标。行计数指定了受insert、update和delete语句影响的行数。您正在使用select语句

cur.execute('select * from table1')
result = cur.fetchall()
print (len(result)) # this will return number of records affected by select statement
print (result)

文档说明cursor.rowcount指定当前已提取的行数。调用cursor.execute()后,立即没有提取任何行,因此结果为0。如果您调用cursor.fetchone(),那么结果将是1,如果您调用cursor.fetchmany(5),那么结果将是6,依此类推(当然,假设有足够的行来满足您的请求!)。

如果在
打印(cur.fetchall())
之后
打印(str(cur.rowcount))
?@CristiFati是,那么它会打印。为什么会有这种行为?这是cx\U Oracle软件包中的要求吗?在pymysql包中,不需要这样做,我从未使用过cx_Oracle(至少不是直接使用)。但是,引用文档(您提供的链接):“此只读属性指定当前从游标中获取的行数…”。关于pyMySQL,我对此一无所知,但它们是两个单独的包,包装着两个不同的DB系统。。。。我认为没有任何限制让他们以同样的方式行事。我不认为这是真的。文档中说
此只读属性指定了当前从游标中获取的行数(对于select语句)
您的问题在这里解释:[link]()
cur.execute('select * from table1')
result = cur.fetchall()
print (len(result)) # this will return number of records affected by select statement
print (result)