Python and PL/SQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vb_bv

    #1

    Python and PL/SQL

    Does Pyton PL/SQL programming language of Oracle support?

    Thx

  • infidel

    #2
    Re: Python and PL/SQL


    vb_bv wrote:[color=blue]
    > Does Pyton PL/SQL programming language of Oracle support?
    >
    > Thx[/color]

    PL/SQL is only supported *inside* Oracle databases. Python can be used
    to call PL/SQL procedures (I recommend the cx_Oracle module), but you
    can't run Python inside the database like PL/SQL.

    Comment

    • Gerhard Häring

      #3
      Re: Python and PL/SQL

      vb_bv wrote:[color=blue]
      > Does Pyton PL/SQL programming language of Oracle support?[/color]

      Python supports calling Oracle PL/SQL procedures. Here's an example
      using the cx_Oracle database adapter:
      [color=blue][color=green][color=darkred]
      >>> import cx_Oracle
      >>> con = cx_Oracle.conne ct("outlinetes t/soca@soca_tsn")
      >>> cur = con.cursor()
      >>> cur.execute("""[/color][/color][/color]
      .... BEGIN
      .... PKG_Test.Test;
      .... END;
      .... """)

      cx_Oracle also works with all types I needed, including passing ARRAYs
      to stored procedures, and getting REFCURSORs back.

      -- Gerhard

      Comment

      • Gerhard Häring

        #4
        Re: Python and PL/SQL

        infidel wrote:[color=blue]
        > vb_bv wrote:
        >[color=green]
        >>Does Pyton PL/SQL programming language of Oracle support?
        >>[/color]
        > PL/SQL is only supported *inside* Oracle databases. Python can be used
        > to call PL/SQL procedures (I recommend the cx_Oracle module), but you
        > can't run Python inside the database like PL/SQL.[/color]

        If one is really really really insisting on running Python code inside
        an Oracle database, I think it could be done: you can write Oracle
        stored procedures in C libraries, Java libraries and even .NET libraries
        (10g on win32). And there are Python implementations for C, Java and .NET.

        So much for the theory.

        In my not so humble opinion, instead of all this fancy stuff, you will
        be better off writing your stored procedures in PL/SQL, which is a very
        good language for manipulating data, and writing portable, efficient and
        maintainable server-side database code.

        -- Gerhard

        Comment

        • Jorge Godoy

          #5
          Re: Python and PL/SQL

          Gerhard Häring <gh@ghaering.de > writes:
          [color=blue]
          > In my not so humble opinion, instead of all this fancy stuff, you will be
          > better off writing your stored procedures in PL/SQL, which is a very good
          > language for manipulating data, and writing portable, efficient and
          > maintainable server-side database code.[/color]

          And if Python is the requirement, but not Oracle, one can write "stored
          procedures" (functions is the name) in Python with PostgreSQL. ;-)

          --
          Jorge Godoy <godoy@ieee.org >

          Comment

          • vb_bv

            #6
            Re: Python and PL/SQL

            Thanks for your answers.
            I would like to document with Python PL/SQL of programs, so similarly
            as javadoc for Java.
            I do not know whether it is possible. If yes, I would like to know how.

            Thx

            Comment

            • Diez B. Roggisch

              #7
              Re: Python and PL/SQL


              vb_bv wrote:[color=blue]
              > Thanks for your answers.
              > I would like to document with Python PL/SQL of programs, so similarly
              > as javadoc for Java.
              > I do not know whether it is possible. If yes, I would like to know how.[/color]


              Is it possible - yes. Has it been done? I doubt it. You can fetch the
              sourcecode of oracle packages through sql-statements (google for how to
              do it), and then process it with whatever tool you like. But you will
              have to write your own parser and generator for that, pydoc or epydoc
              won't be of much use here. However, implementing such a thingy in
              python is certainly a good idea.

              Diez

              Comment

              • infidel

                #8
                Re: Python and PL/SQL

                > Thanks for your answers.[color=blue]
                > I would like to document with Python PL/SQL of programs, so similarly
                > as javadoc for Java.
                > I do not know whether it is possible. If yes, I would like to know how.[/color]

                All of the source code for procedures and packages in an oracle
                database can be retreived from the USER_SOURCE view. It's just plain
                text, though, and one record per line. Parsing it for documentation
                would be up to you.

                There are other views that might be useful too, like USER_TABLES,
                USER_TAB_COLUMN S, USER_OBJECTS, USER_PROCEDURES , USER_ARGUMENTS, etc
                etc etc

                Comment

                Working...