问题标签 [cx-oracle]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1280 浏览

python - python中使用cx_Oracle的异常绑定变量

好的,所以我已连接到针对即时客户端 11.2 编译的 python 2.7 和 cx_Oracle 5.1 中的 Oracle 数据库。我有一个指向数据库的游标,运行 SQL 不是问题,除了这个:

或者

两者都导致来自 oracle 的错误:

在跑步的时候:

完美运行。绑定该变量有什么问题?

0 投票
1 回答
650 浏览

python - 我有一个 Oracle Stack 跟踪文件 Python cx_Oracle

我的 python 应用程序快死了,正在生成这个 oracle 跟踪文件。我正在使用 cx_Oracle,如何使用此跟踪文件来解决此崩溃?

ora_18225_139690296567552.trc kpedbg_dmp_stack()+ 360 <-kpeDbgCrash()+ 192 <-kpureq2()+ 3194 <-OCIStmtPrepare2()+ 157 <-Cursor_InternalPrepare()+ 298 <-0000000000EA3010 <-0000000000EA3010 <-0000000000EA3010 <-0000000000EA3010 < - 000000000000a3010 <-000000000000aea3010 <-00000000000000aea3010 <-00000000000000aea3010 <-000000000000000000A3010 <-000000000000000000A3010 <-0000000000000000000000AEA3010 <-000000000000000000000000000000000000000000000000000000000000000000000000000000来源

0 投票
1 回答
513 浏览

django - 为什么 django 会忽略一些环境变量,除非我在重启时将它们传递给 httpd?

这是我的应用环境:

问题:从 Web 浏览器访问我的 django 网站失败,因为 cx_Oracle 无法获取 Oracle 句柄。

测试:

  1. 运行 django-admin.py shell 来查询 db DOES WORK(从设置了 ORACLE_HOME 和 LD_LIBRARY_PATH 变量的 bash 会话运行)
  2. 运行自定义脚本,将 ORACLE_HOME 和 LD_LIBRARY_PATH 添加到 os.environ 并使用 cx_Oracle 连接到 DB,而不使用 django DOES WORK(从设置了 ORACLE_HOME 和 LD_LIBRARY_PATH 变量的 bash 会话运行)
  3. 使用“sudo -u apache”运行相同的自定义脚本不起作用
  4. 使用“sudo -u env ORACLE_HOME=foo LD_LIBRARY_PATH=foo myscript.py”运行相同的自定义脚本确实有效
  5. 修改 django.db.backends.oracle.base.py 以便在 Database.connect 语句之前,我将 os.environ 打印到一个文件中,显示我已经正确设置了 ORACLE_HOME 和 LD_LIBRARY_PATH
  6. 在 adhoc django wsgi.py 脚本中的 os.environment 中显式设置 ORACLE_HOME 和 LD_LIBRARY_PATH 不起作用
  7. 使用“sudo env ORACLE_HOME=foo LD_LIBRARY_PATH=foo /etc/init.d/httpd restart”重新启动 httpd 确实有效

我的问题是:为什么测试 7 与测试 2、5、6 不同?换句话说,为什么我必须将 env vars 传递给父 httpd 进程,而不仅仅是在 python/django 脚本中设置它们?

0 投票
2 回答
63649 浏览

python - cx_Oracle 和异常处理 - 好的做法?

我正在尝试使用 cx_Oracle 连接到 Oracle 实例并执行一些 DDL 语句:

但是,我不太确定这里异常处理的最佳设计是什么。

首先,我db在 try 块中创建对象,以捕获任何连接错误。

但是,如果它无法连接,那么db将不会存在进一步向下 - 这就是我在db = None上面设置的原因。然而,这是好的做法吗?

理想情况下,我需要捕获连接错误,然后是运行 DDL 语句的错误,等等。

嵌套异常是个好主意吗?或者有没有更好的方法来处理这样的依赖/级联异常?

此外,我希望脚本在某些部分(例如连接失败)中终止 - 因此被注释掉的sys.exit()调用。但是,我听说像这样对流控制使用异常处理是不好的做法。想法?

0 投票
1 回答
4157 浏览

python - cx-oracle 中的并行执行

我最近加入了一家新公司,并且不熟悉 python(他们首选的脚本语言),并且一直在使用 cx_oracle 创建一些 ETL 流程。到目前为止,我构建的脚本都是单线程作业,它们从 Oracle 源数据库中选择我需要的列子集,并将输出写入命名管道,其中外部进程正在等待读取该数据并将其插入目标.

这一直很好,直到我得到一些在 5 亿 -20 亿行范围内的表。这项工作仍然有效,但需要很多小时才能完成。这些大型源表是分区的,所以我一直在尝试研究协调不同分区的并行读取的方法,这样我就可以让两个或多个线程同时工作,每个线程都写入一个单独的命名管道。

cx-oracle 中是否有一种优雅的方式来处理从同一个表的不同分区读取的多个线程?

这是我当前的(简单)代码:

我的一些源表有超过 1000 个分区,因此硬编码分区名称不是首选选项。我一直在考虑设置分区名称数组并遍历它们,但如果人们有其他想法,我很乐意听到它们。

0 投票
2 回答
22895 浏览

python - 从 cx_oracle 执行一个 sql 脚本文件?

有没有办法在 python 中使用 cx_oracle 执行 sql 脚本文件。

我需要在 sql 文件中执行我的创建表脚本。

0 投票
6 回答
3703 浏览

python - How do I retrieve data from Oracle as a query result using an anonymous PL/SQL block in Python?

All the examples of using PL/SQL I can find end up looking like this (this example taken from Wikipedia):

In other words, they all have one thing in common: when it comes time to actually output the data somewhere, they stick it in DBMS_OUTPUT, which seems to be a pretty useless place for an application to process it.

If I wanted to retrieve data from an Oracle database using a PL/SQL feature as if this data were the result of a plain SQL query, how would I do it? For example, if I wanted to process the rows deleted by a DELETE ... RETURNING ... INTO SQL statement in the same way that I would process the results of SELECT ... FROM ...?

I do not want to modify the schema of the database or create any stored procedures; I'd just like to do cursor.execute("begin; ... something; end"); results = cursor.fetchall().

Particularly, I do not want to create a variable with cursor.var(), since that API is not portable between database implementations. (Obviously the SQL won't be portable either, but it's a generally accepted fact that one needs to generate custom SQL strings for different database backends no matter what.)

0 投票
1 回答
5815 浏览

python - cx_Oracle - encoding query result to Raw

EDIT:

The following print shows my intended value.

(both sys.stdout.encoding and sys.stdin.encoding are 'UTF-8').

Why is the variable value different than its print value? I need to get the raw value into a variable.

Original question:

I'm having an issue querying a BD and decoding the values into Python.

I confirmed my DB NLS_LANG using

where

I've both tried (which return the same)

where

how to get the queries result back to the proper 'João' ?

0 投票
2 回答
7006 浏览

python - cx_Oracle.so:未定义符号:PyUnicodeUCS2_AsEncodedString

我在安装 cx_oracle 时遇到问题。我已经安装了 oracle instantclient 和 cx_oracle oracle 软件包,我在导入 cx_oracle 时遇到了这个错误。我正在运行 ubuntu 11.10 作为主机。

任何人都知道如何解决这个问题

干杯

0 投票
2 回答
956 浏览

python - 从 cx_Oracle 内部使用 SQL*PLUS COPY?

我们需要在两个 Oracle 数据库模式之间复制记录。

手动,我们可以使用 SQL*PLUS COPY 命令执行此操作:

http://www.oracleutilities.com/SQLPLus/copy.html

但是,如果可能,我们希望使用 cx_Oracle 自动执行此操作(我们还需要做一些其他事情 - 例如 SSH 交互,因此使用 Python 和 cx_Oracle)。

但是,如果我尝试在 cx_Oracle 中执行 COPY,它似乎不喜欢该命令:

我猜这是因为 COPY 是 SQL*PLUS 特定命令,而不是标准 SQL 规范的一部分?

无论如何,有没有办法让 COPY 命令(或任何其他 SQL*PLUS 特定扩展)在 cx_Oracle 下工作?

我相信可以使用 INSERT INTO...SELECT 来实现类似的效果,但是如果有问题的两个数据库位于不同的 Oracle 实例或主机上,则需要一个数据库链接,并且我们并不总是有权创建这些链接。

干杯,维克多