Forum Stats

  • 3,768,544 Users
  • 2,252,807 Discussions
  • 7,874,616 Comments

Discussions

Python

726038
726038 Member Posts: 3
edited Nov 12, 2009 9:39AM in Python
I have a simple stored procedure as such:

create or replace procedure tdate as

v_out number;

begin

select date_to_ts(sysdate)
into v_out
from dual;

dbms_output.put_line(v_out);

end;
/

Which returns the following from within SQL Plus:
exec tdate;
1257275103

I want to know how to execute this stored procedure in a Python Script to return the
value it returns in SQL Plus.

Can anyone help with this.

Also do you know of any documentation with examples of how to do this?

Thanks in advance

Answers

  • 402929
    402929 Member Posts: 6
    If you need a return value and don't need just side efect you have to write a function

    using Cx_Oracle your script should be something like

    conn=connection(....)
    cur=conn.cursor()
    cur.execute("select WhateverFunctionYouNeed() from dual")
    row=cur.fetchone()
    cur.close()
    conn.close()

    row[0]
    # this is the value you want
This discussion has been closed.