This article mainly introduces Python's method of invoking Oracle stored procedures using Cx_oracle, and analyzes the specific steps and related operation techniques of Python to call PL/SQL through cx_oracle with specific examples, and the friends you need can refer to the following
This example describes how Python uses cx_oracle to invoke Oracle stored procedures. Share to everyone for your reference, as follows:
Here the main test is to call PL/SQL in Python via cx_oracle .
First, create a simple stored procedure on the database side.
Create or Replace procedure test_msg (I_user in Varchar2, o_msg out varchar2) isbegin o_msg: = I_user | | ', good morning! '; End
Then, start the stored procedure call on the Python command line.
Import cx_oracle as Cxconn = cx.connect (' Database connecting string ') cursor = conn.cursor () #声明变量user = ' Nick ' #plsql入参msg = Cursor.var (cx_oracle.string) #plsql出参 # Call stored procedure 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 a conversion relationship between the stored procedure, cx_oracle, and Python object types. Specific as follows:
| Oracle |
cx_oracle |
Python |
| VARCHAR2, NVARCHAR2, LONG |
cx_oracle.string |
str |
| char |
cx_oracle.fixed_char |
str |
| number |
cx_oracle.number |
int |
| float |
cx_oracle.number |
FLOAT |
| DATE |
Cx_oracle.datetime |
datetime.datetime |
| TIMESTAMP |
cx_oracle.timestamp |
datetime.datetime |
| CLOB |
cx_oracle.clob |
cx_oracle.lob |
| BLOB |
Cx_oracle.blob |
Cx_oracle.lob |