import cx_Oracle as cx
import datetime
def execute_sql():
# 声明变量
date_time = datetime.datetime.now().strftime('%Y-%m')
# 连接数据库
conn = cx.connect('username/password@host/orcl')
# 创建游标
cur = conn.cursor()
# 调用存储过程
try:
# 传递参数进去
cur.callproc('存储过程名称', [date_time])
# 不传递参数
cur.callproc('存储过程名称')
except Exception as e:
print(str(e))
# 资源关闭
cur.close()
conn.commit()
conn.close()
if __name__ == "__main__":
execute_sql()