无法在 cx_oracle 中 "set define off";

Unable to "set define off" in cx_oracle;

我正在尝试从 python 执行一些 SQL 语句,但在 SQL 的以下行遇到问题:

关闭定义;

其他SQL个语句没有此类问题。

def Querydf(command_str, dsn_str, username, pw):  
    #function outputs data as a pandas dataframe
    conn = cx_Oracle.connect(user = username, password = pw, dsn=dsn_str)
    cursor = conn.cursor()

    cmd = command_str.split(";")
    if (len(cmd)>1):
        for i in cmd:
            temp = i.replace("\n","")
            print(temp)
            cursor.execute(temp)
    else:
        cursor.execute(command_str)

    Data = cursor.fetchall()
    col_names = []
    for i in range(0, len(cursor.description)):
        col_names.append(cursor.description[i][0])
    dataframe =  pd.DataFrame(data = Data, columns = col_names)
    cursor.close()
    conn.close()
    return dataframe

返回的错误是: cx_Oracle.DatabaseError: ORA-00922: 选项缺失或无效

如果有人能对此提供一些见解,那就太好了,谢谢!

命令"set define off"不是SQL语句,而是SQL*Plus语句。因此,它只能在 SQL*Plus 中执行。由于 cx_Oracle 仅处理 SQL 语句,因此在任何情况下都不需要此命令!如果您正在读取包含 SQL 语句的文件,这些语句通常是 运行 by SQL*Plus,您需要过滤掉这些语句。