在 Python 中调用 Oracle 存储过程时出现错误“不支持字典类型的值”

问题描述 投票:0回答:2

使用 cx_oracle 调用 Oracle 存储过程时,出现以下错误 Python value of type dict not supported.

我的代码如下-

try:
    cursor = connection.cursor()
    cursor.callproc("my_proc", [fname, hash, json])
    cursor.close()
    connection.commit()
finally:
    connection.close()

在我的存储过程中,我在 Clob 中传递了两个字符串(Oracle 中的 varchar2)和 json 数据。

请注意,我是 Python 的新手,但仍在掌握它。

python oracle python-2.7 cx-oracle
2个回答
0
投票

试试这个:

try:
cursor = connection.cursor()
cursor.callproc("my_proc", json.dumps([fname, hash, json]))
cursor.close()
connection.commit()

最后: connection.close()


-1
投票

这似乎对我有用。如果您更详细地更新您的问题,我们也许能够发现您的问题

cursor = connection.cursor()
cursor.execute("""
               create or replace procedure my_proc (
                   p1 in varchar2,
                   p2 in varchar2,
                   p3 in clob,
                   p4 out varchar2
               ) as
               begin
                 p4 := p1 || p2 || p3;
               end;
               """)

hash = "abc"
fname = "def"
json = "ghi"
with connection.cursor() as cursor:
    myout = cursor.var(cx_Oracle.STRING)
    cursor.callproc("my_proc", [fname, hash, json, myout])
    print(myout.getvalue())

输出为:

defabcghi
© www.soinside.com 2019 - 2024. All rights reserved.