【问题标题】:How to return a SQLPLUS variable in Python using cxOracle如何使用 cx_Oracle 在 Python 中返回 SQLPLUS 变量
【发布时间】:2012-07-24 14:31:57
【问题描述】:

我有以下 SQLPlus 语法。现在我需要使用 cxOracle 在 Python 中运行它。我该怎么做?

variable my_cnt number;
begin
   :my_cnt := 10;
    commit;
end;
.
/
select :my_cnt from dual;

【问题讨论】:

    标签: python oracle sqlplus


    【解决方案1】:

    给你。

    import cx_Oracle
    connstr = 'scott/tiger@127.0.0.1:1521/xe'
    orcl = cx_Oracle.connect(connstr)
    
    curs = orcl.cursor()
    number_var = curs.var(cx_Oracle.NUMBER)
    curs.execute(r"""BEGIN :my_cnt := 10; END;""", {'my_cnt':number_var})
    
    print number_var.getvalue()
    
    curs.close()
    orcl.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-13
      • 2017-07-02
      • 1970-01-01
      • 2015-05-15
      • 2015-12-28
      • 1970-01-01
      相关资源
      最近更新 更多