我正在为python日志记录模块处理一个处理程序.这基本上记录到oracle数据库.
我正在使用cx_oracle,当表为空时,我不知道如何获取的是列值.
cursor.execute('select * from FOO')
for row in cursor:
# this is never executed because cursor has no rows
print '%s\n' % row.description
# This prints none
row = cursor.fetchone()
print str(row)
row = cursor.fetchvars
# prints useful info
for each in row:
print each
Run Code Online (Sandbox Code Playgroud)
输出是:
None
<cx_Oracle.DATETIME with value [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None
, None, None, None, None, None, None, None, None, None, None, None, None, None, …Run Code Online (Sandbox Code Playgroud) 当我使用Python解释器运行它时,我的python程序(Python 2.6)工作正常,它连接到Oracle数据库(10g XE)而没有错误.但是,当我使用py2exe编译它时,可执行版本在调用cx_Oracle.connect()时失败并显示"无法获取Oracle环境句柄".
我没有高兴地试过以下事情:
ORACLE_HOME以及PATH我的测试用例:
testora.py:
import cx_Oracle
import decimal # needed for py2exe to compile this correctly
def testora():
"""testora
>>> testora.testora()
<cx_Oracle.Connection to scott@localhost:1521/orcl>
X
"""
orcl = cx_Oracle.connect('scott/tiger@localhost:1521/orcl')
print orcl
curs = orcl.cursor()
result = curs.execute('SELECT * FROM DUAL')
for (dummy,) in result:
print dummy
if __name__ == '__main__':
testora()
Run Code Online (Sandbox Code Playgroud)
build_testora.py:
from distutils.core import setup
import py2exe, sys
sys.argv.append('py2exe')
setup(
options = {'py2exe': {
'bundle_files': 2,
'compressed': True …Run Code Online (Sandbox Code Playgroud) 我试图在python和oracle db之间调用存储过程.我遇到的问题是将光标传递给参数.
Oracle存储过程基本上是:
create or replace procedure sp_procedure(
cid int,
rep_date date,
ret out sys_refcursor
) is
begin
open ret for
select
...
end;
Run Code Online (Sandbox Code Playgroud)
调用数据库的python代码是:
import cx_Oracle
from datetime import date
connstr='user/pass@127.0.0.1:2521/XE'
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()
cid = 1
rep_date = date(2011,06,30)
curs.callproc('sp_procedure', (cid, rep_date, curs))
Run Code Online (Sandbox Code Playgroud)
错误是:
curs.callproc('sp_procedure', (cid, rep_date, curs))
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
Run Code Online (Sandbox Code Playgroud)
我也试过传递一个字典作为keywordsParameters:
cid = 1
rep_date = date(2011,06,30)
call_params = {'cid': cid, 'rep_date': rep_date, 'ret': curs}
curs.callproc('sp_procedure', (cid, rep_date, curs), call_params)
Run Code Online (Sandbox Code Playgroud)
返回相同的错误.
谢谢.
我有安装cx_oracle的问题.我安装了oracle instantclient和cx_oracle oracle软件包安装后我在导入cx_oracle时收到此错误.我正在运行ubuntu 11.10作为主机.
import cx_Oracle
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: /usr/lib/python2.7/dist-packages/cx_Oracle.so: undefined symbol:PyUnicodeUCS2_AsEncodedString
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何解决这个问题
干杯
我已经安装了oracle客户端和oracle client-dev,并设置了ORACLE_HOME环境变量.然而,当我尝试安装tux_oracle(python setup.py build)时,我得到以下内容:致命错误:oci.h:没有这样的文件或目录
我正在开发一个系统的一部分,其中进程限制在大约350MB的RAM; 我们使用cx_Oracle从外部系统下载文件进行处理.
外部系统将文件存储为BLOB,我们可以抓住它们执行以下操作:
# ... set up Oracle connection, then
cursor.execute(u"""SELECT filename, data, filesize
FROM FILEDATA
WHERE ID = :id""", id=the_one_you_wanted)
filename, lob, filesize = cursor.fetchone()
with open(filename, "w") as the_file:
the_file.write(lob.read())
Run Code Online (Sandbox Code Playgroud)
lob.read()MemoryError当我们点击一个大于300-350MB的文件时,显然会失败,所以我们尝试过这样的东西,而不是一次性读取所有内容:
read_size = 0
chunk_size = lob.getchunksize() * 100
while read_size < filesize:
data = lob.read(chunk_size, read_size + 1)
read_size += len(data)
the_file.write(data)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我们仍然MemoryError经历了几次迭代.从时间开始lob.read(),以及我们最终获得的内存不足情况,看起来好像每次都lob.read()从数据库中提取(chunk_size + read_size)字节.也就是说,即使缓冲区相当小,读取也需要O(n)时间和O(n)存储器.
为了解决这个问题,我们尝试过类似的方法:
read_size = 0
while read_size < filesize:
q = u'''SELECT dbms_lob.substr(data, 2000, …Run Code Online (Sandbox Code Playgroud) 我需要将以下值替换为select查询.但我得到了错误,如下所述
self.jobNo = J-12060
qcActivity = C173
self.wrkArea = 1666339
cursor.execute("""SELECT A.MARKERID, D.COMMENTS,A.STATUS,A.X1,A.Y1,A.X2,A.Y2,C.ERRGROUP,C.ERRDESC,c.category
FROM MDP_ERR_MASTER A,(SELECT MARKERID, MAX(RECNO) maxRECNO FROM MDP_ERR_MASTER where project_code = ':jobno'
and errorcode like ':jobno_:qcActivity%' AND WORKAREA LIKE ':workarea%'
GROUP BY MARKERID) B,MDP_ERR_CONFIG C,(SELECT MARKERID, COMMENTS FROM MDP_ERR_MASTER WHERE PROJECT_CODE = ':jobno'
AND RECNO = 1 AND errorcode like ':jobno_:qcActivity%' AND WORKAREA LIKE ':workarea%') D
WHERE(A.MARKERID = B.MARKERID And A.RECNO = B.maxRECNO And A.Markerid = D.MARKERID)AND A.PROJECT_CODE = ':jobno'
AND A.ERRORCODE LIKE ':jobno_:qcActivity%' AND A.WORKAREA LIKE …Run Code Online (Sandbox Code Playgroud) 据我了解,有一些与SIP有关的变化使得安装这一点变得困难.
这些页面有安装的背景和建议.http://sourceforge.net/p/cx-oracle/mailman/message/34534872/,http://stefanoapostolico.com/2015/10/08/install_cx_oracle_with_sip_enabled.html
把所有这些放在一起,这是我最好的把它安装到我的virtualenv,但唉,仍然没有好处.
我得到的错误是:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(/Users/me/sx_direct_env/lib/python2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /b/227/rdbms/lib/libclntsh.dylib.10.1
Referenced from: /Users/me/sx_direct_env/lib/python2.7/site-packages/cx_Oracle.so
Reason: image not found
Run Code Online (Sandbox Code Playgroud)
以下是我的所有安装步骤:
$ cd /Users/me/sx_direct_env/lib/python2.7
$ mkdir oracle
$ cd oracle
$ export ORACLE_HOME=$PWD
$ export DYLD_LIBRARY_PATH=$ORACLE_HOME
$ export LD_LIBRARY_PATH=$ORACLE_HOME
$ export PATH=$PATH:$ORACLE_HOME
$ unzip ~/Downloads/instantclient-basic-macos.x64-11.2.0.4.0.zip
$ unzip ~/Downloads/instantclient-sdk-macos.x64-11.2.0.4.0.zip
$ mv instantclient_11_2/* .
$ rmdir instantclient_11_2
$ curl -O https://raw.githubusercontent.com/kubo/fix_oralib_osx/master/fix_oralib.rb
$ ruby -a fix_oralib.rb
adrci:
add rpath: @loader_path
change …Run Code Online (Sandbox Code Playgroud) 我安装了cx_Oracle,我可以成功导入它.但是当我尝试建立Oracle连接时,我收到此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle
我的操作系统是MacOSX,我的ORACLE_HOME指向instantclient_11_2.
我正在尝试安装 cx_Oracle,但收到此错误,\n我安装了最新的 setuptools 和 pip。\n有人遇到过类似的问题吗?他们是如何解决的?
\n我有 Visual Studio:请参见图片
\n
Processing c:\\....resources\\cx_oracle-8.1.0.tar.gz\n Installing build dependencies ... done\n Getting requirements to build wheel ... done\n Preparing metadata (pyproject.toml) ... done\nBuilding wheels for collected packages: cx_Oracle\n Building wheel for cx_Oracle (pyproject.toml) ... error\n error: subprocess-exited-with-error\n\n \xc3\x97 Building wheel for cx_Oracle (pyproject.toml) did not run successfully.\n \xc2\xa6 exit code: 1\n ?-> [7 lines of output]\n C:\\....\\2\\pip-build-env-806_5jc6\\overlay\\Lib\\site-packages\\setuptools\\config\\expand.py:144: UserWarning: File \'C:\\\\....\\\\2\\\\pip-install-r8jb3ohi\\\\cx-oracle_111cfa7e3d91425bb65e9a6baa89c82f\\\\README.md\' cannot be found\n warnings.warn(f"File {path!r} cannot be found")\n running bdist_wheel\n running build\n running …Run Code Online (Sandbox Code Playgroud)