Home  >  Article  >  Backend Development  >  Example of how Python uses cx_Oracle to call Oracle stored procedures

Example of how Python uses cx_Oracle to call Oracle stored procedures

黄舟
黄舟Original
2017-10-09 10:36:283668browse

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 &#39;Nick, Good Morning!&#39;>
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:

##VARCHAR2, NVARCHAR2, LONG cx_Oracle.STRINGstrCHARcx_Oracle.FIXED_CHARstrNUMBERcx_Oracle.NUMBERintFLOATcx_Oracle.NUMBERfloatDATEcx_Oracle.DATETIMEdatetime.datetimeTIMESTAMPcx_Oracle.TIMESTAMPdatetime.datetimeCLOBcx_Oracle.CLOBcx_Oracle.LOBBLOBcx_Oracle.BLOBcx_Oracle.LOB
Oracle cx_Oracle Python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn