python - 无法在 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: missing or invalid option
如果有人能对此提供一些见解,那就太好了,谢谢!
解决方案
“set define off”命令不是 SQL 语句,而是 SQL*Plus 语句。因此,它只能在 SQL*Plus 中执行。由于 cx_Oracle 只处理 SQL 语句,所以无论如何都不需要这个命令!如果您正在读取包含通常由 SQL*Plus 运行的 SQL 语句的文件,则需要过滤掉这些语句。
推荐阅读
- database - 如何使用delphi XE8获取数据库中元素的数量
- javascript - 列出在 AngularJS 中使用 $http.get 创建的列表中的所有元素
- ruby-on-rails - 在 Spree ruby gem 中缓存配置
- sql - 如何根据日期连接多个表中的值
- typescript - 如何使用 vue-class-component 构建 es6 vue-component 库
- java - hibernate.PersistentObjectException:分离的实体传递给持久化
- swift - swift3中的字符串变量比较
- php - Laravel 中间件无法正常用于检查权限
- node.js - 如何禁用默认的 BotBuilder 日志
- artifactory - 如何使用自己的域名从工件存储库中获取工件?