Call oracle stored procedure with cursor output parameter from python script

风流意气都作罢 提交于 2019-12-21 20:18:23

问题


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 <cx_Oracle.Connection to login@db_name>>

What am I doing wrong?

Thanks.


回答1:


I've just had similar issue. cur_var has type <type 'cx_Oracle.CURSOR'> and cur_var.getvalue() gets object of type <type 'OracleCursor'>. 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!



来源:https://stackoverflow.com/questions/19095690/call-oracle-stored-procedure-with-cursor-output-parameter-from-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!