简体   繁体   中英

Unable to “set define off” in cx_oracle;

I am trying to execute some SQL statements from python but met with issues on the following line of SQL:

set define off;

Other SQL statements do not have such issues.

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

The error returned is: cx_Oracle.DatabaseError: ORA-00922: missing or invalid option

Would be great if anyone can provide some insight on this, thanks!

The command "set define off" is not a SQL statement, but a SQL*Plus statement. As such, it can only be executed in SQL*Plus. Since cx_Oracle only processes SQL statements, this command is unnecessary in any case! If you are reading from a file that contains SQL statements that are normally run by SQL*Plus you'll need to filter these statements out.

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