2 Replies Latest reply: Jun 25, 2009 4:11 AM by Keith Jamieson RSS

    Bind variables in python

    Keith Jamieson
      Hi guys,

      is it possible to use bind-variables within a python script. (python 2.5)

      If so can you show me an example please
        • 1. Re: Bind variables in python
          390020
          Yes, you can and it's pretty simple (works across all versions since it's a package feature):

          $ ipython
          Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
          Type "copyright", "credits" or "license" for more information.

          In [1]: import cx_Oracle as ora

          In [2]: con = ora.connect('myuser', 'mypass', 'mydb')

          In [3]: cur = con.cursor()

          # you can pass positional arguments
          In [4]: cur.execute("select pay_id from usr_payroll where pay_id<:p1", (5,))

          In [5]: cur.fetchall()
          Out[5]: [(1,), (2,), (3,), (4,)]

          # you can pass named arguments, too
          In [6]: cur.execute("select pay_id from usr_payroll where pay_id<:p1", {'p1':5})

          In [7]: cur.fetchall()
          Out[7]: [(1,), (2,), (3,), (4,)]
          • 2. Re: Bind variables in python
            Keith Jamieson
            Thanks for that. I'll pass it on to appropriate people