python连oracle数据库参数变量_Python cx_Oracle绑定变量

本文介绍了Python新手在使用cx_Oracle连接Oracle数据库时遇到的绑定变量问题。当使用一个字典和两个相同的命名变量时,出现错误。解决方案包括通过元组、关键字参数或字典正确地绑定变量。同时指出,虽然可以通过传递一个包含单个值的元组来绑定单个变量,但将字典直接传递给SQL语句也是支持的。
摘要由CSDN通过智能技术生成

I am a Python newbie, I am having troubles in the use of bind variables. If I execute the code below everything works fine.

bind= {"var" : "ciao"}

sql = "select * from sometable where somefield = :bind"

cur.prepare(sql)

cur.execute(sql,bind)

Instead if I add another bind variable I obtain an error.

bind= {"var" : "ciao"}

sql = "select * from sometable where somefield = :bind and otherfield = :bind"

cur.prepare(sql)

cur.execute(sql,(bind,bind))

cur.execute(sql,(bind,bind))

Oracle.NotSupportedError: Variable_TypeByValue(): unhandled data

I have solved it with

cur.execute(sql,(bind["var"],bind["var"]))

but I can't understand why the previous command was not ok.

Which is the correct

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值