本文测试在Python中通过cx_Oracle调用PL/SQL。
首先,在数据库端创建简单的存储过程。
create 或是replace procedure test_msg (i_user varchar2,拷贝,o_msg out varchar2), 开始 o_msg 才能;:=,i_user | |”, Good ,早上好!”; 结束;
然后,开始在Python命令行中进行存储过程调用。
import cx_Orace as 残雪 时间=conn cx.connect (“database connecting 字符串”) 时间=cursor conn.cursor () #声明变量 时间=user “尼克”,# plsql入参 时间=msg cursor.var (cx_Oracle.STRING), # plsql出参 #调用存储过程 cursor.callproc (“test_msg”,[用户,味精]),#【“尼克”,“尼克,,Good ,早上好!”) #打印返回值 print msg # & lt; cx_Oracle.STRING  with value “早上场所看到尼克,Good  !”在 print msg.getvalue(), #尼克,,Good ,早上好! #资源关闭 cursor.close () conn.close ()
延伸
存储过程,cx_Oracle, Python的对象类型之间存在转换关系,具体如下:
<强>甲骨文强>
<强> cx_Oracle 强>
<强> Python 强>
VARCHAR2
NVARCHAR2长
字符
cx_Oracle.FIXED_CHAR
数量cx_Oracle.NUMBER int
浮动浮动日期
cx_Oracle.DATETIME datetime.datetime
时间戳cx_Oracle.TIMESTAMP CLOB
cx_Oracle.CLOB cx_Oracle.LOB
cx_Oracle BLOB。BLOB