This article mainly introduces how Python uses cx_Oracle to call Oracle stored procedures. It analyzes the specific steps and related operating techniques of calling PL/SQL through cx_Oracle in Python based on specific examples. Friends in need can refer to it
The example in this article describes how Python uses cx_Oracle to call Oracle stored procedures. Share it with everyone for your reference, the details are as follows:
The main test here is to call PL/SQL through cx_Oracle in Python.
First, create a simple stored procedure on the database side.
create or replace procedure test_msg(i_user in varchar2, o_msg out varchar2) is begin o_msg := i_user ||', Good Morning!'; end;
Then, start making stored procedure calls in the Python command line.
import cx_Oracle as cx conn = cx.connect('database connecting string') cursor = conn.cursor() #声明变量 user = 'Nick' #plsql入参 msg = cursor.var(cx_Oracle.STRING) #plsql出参 #调用存储过程 cursor.callproc('test_msg', [user, msg]) #['Nick', 'Nick, Good Morning!'] #打印返回值 print msg #<cx_Oracle.STRING with value 'Nick, Good Morning!'> print msg.getvalue() #Nick, Good Morning! #资源关闭 cursor.close() conn.close()
Extended reading:
There is conversion between stored procedures, cx_Oracle, and Python object types relation. The details are as follows:
Oracle | cx_Oracle | Python |
cx_Oracle.STRING | str | |
cx_Oracle.FIXED_CHAR | str | |
cx_Oracle.NUMBER | int | |
cx_Oracle.NUMBER | float | |
cx_Oracle.DATETIME | datetime.datetime | |
cx_Oracle.TIMESTAMP | datetime.datetime | |
cx_Oracle.CLOB | cx_Oracle.LOB | |
cx_Oracle.BLOB | cx_Oracle.LOB |
The above is the detailed content of Example of how Python uses cx_Oracle to call Oracle stored procedures. For more information, please follow other related articles on the PHP Chinese website!