python调用oracle的存储过程_从python脚本使用光标输出参数调用oracle存储过程

I am trying to call a oracle stored procedure with 2 in and 1 out parameter from python script. The problem I am having is passing a cursor out-parameter.

The Oracle stored procedure is essentially:

PROCEDURE ci_lac_state

(LAC_ID_IN IN VARCHAR2,

CI_ID_IN IN VARCHAR2 DEFAULT NULL,

CGI_ID OUT SYS_REFCURSOR)

AS

BEGIN

OPEN cgi_id FOR

...

END;

The python code calling to the database is:

#! /usr/bin/python

import cx_Oracle

lac='11508'

ci='9312'

try:

my_connection=cx_Oracle.Connection('login/passwd@db_name')

except cx_Oracle.DatabaseError,info:

print "Logon Error:",info

sys.exit()

my_cursor=my_connection.cursor()

cur_var=my_cursor.var(cx_Oracle.CURSOR)

my_cursor.callproc("cgi_info.ci_lac_state", [lac, ci, cur_var])

print cur_var.getvalue()

And I get such cursor value as the result:

<__builtin__.oraclecursor on to login>>

What am I doing wrong?

Thanks.

解决方案

I've just had similar issue. cur_var has type and cur_var.getvalue() gets object of type . To get data you have to fetched them from the OracleCursor object. Try for example:

print cur_var.getvalue().fetchall()

To see more function of OracleCursor object just check its directory:

dir(cur_var.getvalue())

Hope this will help you!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值