python中调用存储过程(oracle)

python需要与oracle数据库进行交互时,需要使用cx_Oracle模块,下面讲解python连接Oracle数据库的方法步骤

#1. 首先需要导入cx_Oracle模块

import cx_Oracle

try:

    #2.创建连接
    conn = cx_Oracle('scott/tiger@localhost/orcl') ##该处填写数据库信息
    #3.创建游标

    cursor = conn.cursor()
    #4.创建sql

    sql = ''
    #5.执行sql
    #执行唯一的sql
    arr = cursor.execute(sql)
    #执行多条数据sql,例如一次插入多条数据

    arr = cursor.executemany(sql,list) #list表示数据,例如列表,列表字典
    #执行存储过程
    arr = cursor.callproc(sql)

    #执行函数

    arr = cursor.callfunc(sql)
    #6.获取结果
    data = arr.fetchall()  ##获取全部结果
    data = arr.fetchone() ##一次获取一条结果

except Exception as e:

    print('{}'.format(e))

finally:
pass

猜你喜欢

转载自blog.csdn.net/qq_39354340/article/details/81060509