Python 获取cx_Oracle.InterfaceError:尝试运行alter system命令时不是查询异常

Python 获取cx_Oracle.InterfaceError:尝试运行alter system命令时不是查询异常,python,oracle,cx-oracle,Python,Oracle,Cx Oracle,我在尝试结束指定用户的所有用户会话时收到cx\u Oracle.interface错误:不是查询错误 import cx_Oracle try: con = cx_Oracle.connect('username/password@someip/ora12c') cursor = con.cursor() result= cursor.execute("select USERNAME,SID,SERIAL#,COMMAND,STATUS from v$session

我在尝试结束指定用户的所有用户会话时收到
cx\u Oracle.interface错误:不是查询
错误

import cx_Oracle

try:
    con = cx_Oracle.connect('username/password@someip/ora12c')
    cursor = con.cursor()

    result= cursor.execute("select USERNAME,SID,SERIAL#,COMMAND,STATUS from v$session where USERNAME='uname'")


    for session in result:
        query_string="ALTER SYSTEM KILL SESSION '@1,@2' IMMEDIATE".replace("@1",str(session[1])).replace("@2",str(session[2]))
        print(query_string)
        cursor.execute(query_string)
        con.commit()

except cx_Oracle.DatabaseError as e:
    print('Unable to kill user sessions, Subsequent steps may FAIL!!')
    print(e)

finally:
    if cursor: cursor.close()
    if con: con.close()
运行我得到的上述代码:

ALTER SYSTEM KILL SESSION '1526,30533' IMMEDIATE
Traceback (most recent call last):
  File "oracleKillSession.py", line 10, in <module>
    for session in result:
cx_Oracle.InterfaceError: not a query
立即更改系统终止会话“152630533”
回溯(最近一次呼叫最后一次):
文件“oracleKillSession.py”,第10行,在
会议结果:
cx_Oracle.InterfaceError:不是查询

我尝试了当时的解决方案,但这无助于解决问题。请提供帮助。

您不能在游标(
用于结果中的会话)上迭代,然后使用同一游标执行语句。为此,您需要一个单独的游标,或者首先需要从游标获取所有行。因此,这两种方法中的一种适用于您:

备选案文1:

alter_cursor = con.cursor()
for session in result:
    alter_cursor.execute(query_string)
备选案文2:

results = cursor.fetchall()
for session in result:
    cursor.execute(query_string)