简体   繁体   English

Python callproc 的 cx_Oracle 输入/输出变量

[英]Python cx_Oracle in/out variables for callproc

I have an oracle procedure that is supposed to return a chunk of json.我有一个 oracle 过程应该返回 json 的块。

The procedure has 4 paramaters该过程有 4 个参数

input is an ID value output json CLOB output some message in json format CLOB output if success or failure varchar2输入是一个 ID 值 output json CLOB output json 格式的一些消息 CLOB output 如果成功或失败 varchar2

so in my code I have done the following just to test if I can successfully call and return it所以在我的代码中我做了以下只是为了测试我是否可以成功调用并返回它

ConnectionString = 'someconnection.connection'
con = cx_Oracle.connect(ConnectionString)
cur = con.cursor()

ID = '51858645'
json_out = cur.var(cx_Oracle.CLOB)
message = cur.var(cx_Oracle.CLOB)
status = cur.var(cx_Oracle.STRING)
oracle_return = cur.callproc('project.getsomejson',[ID,json_out,message,status])

However, it fails and returns但是,它失败并返回

PLS-00306: wrong number or types of arguments in call to 'getsomejson'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

This is the procedure definition这是过程定义

procedure callOracle(json_in clob,json_out out clob,message out clob,status out varchar2)

This is calling an oracle 12c db I'm really not familiar at all with calling procedures in python. Typically I callfunc with the stored type and just get a return这是调用 oracle 12c db 我真的一点都不熟悉 python 中的调用过程。通常我用存储的类型调用 func 并得到一个返回

The procedure is expecting过程期待中

CLOB, CLOB, CLOB, VARCHAR2 CLOB、CLOB、CLOB、VARCHAR2

but you are passing但你路过

VARCHAR2, CLOB, CLOB, VARCHAR2 VARCHAR2、CLOB、CLOB、VARCHAR2

The name you gave (callOracle) also doesn't match what you are calling in Python (project.getsomejson).您提供的名称 (callOracle) 也不匹配您在 Python (project.getsomejson) 中调用的名称。 Perhaps verify that you have the right procedure signature?也许验证你有正确的程序签名? Assuming it is correct, though, you'll need to change the first one to be a CLOB as well or change the stored procedure to accept VARCHAR2.但是,假设它是正确的,您需要将第一个也更改为 CLOB,或者更改存储过程以接受 VARCHAR2。 Something like this should do it:像这样的事情应该这样做:

json_in = conn.createlob(cx_Oracle.DB_TYPE_CLOB)
json_in.write("51858645")
json_out_var = cur.var(cx_Oracle.DB_TYPE_CLOB)
message_var = cur.var(cx_Oracle.DB_TYPE_CLOB)
status_var = cur.var(str)
cur.callproc(json_in, json_out, message, status)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM