Example of how Python uses cx_oracle to invoke Oracle stored procedures

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.