python - 如何从 Python 脚本中创建存储过程?

标签 python oracle stored-procedures plsql cx-oracle

我正在寻找在 Python 中创建 Oracle 存储过程的方法。

我知道,cx_Oracle 中的 cursor.callproc 存在来调用现有存储过程,但我正在寻找一种在 Python 中创建 Oracle 存储过程的方式/方法.

最佳答案

只需将 execute() 与 SQL CREATE OR REPLACE 命令结合使用即可。

要检查过程是否有效,您需要查询基表,例如 user_errors

with connection.cursor() as cursor:
    cursor.execute("""create or replace procedure x(a in number) as begin BOGUS end;""")
    cursor.execute("""
            select name, type, line, position, text
            from user_errors
            where name = 'X'
            order by name, type, line, position""")
    data = cursor.fetchall()
    print(data) 

输出为:

[('X', 'PROCEDURE', 1, 41, 'PLS-00103: Encountered the symbol "END" when expecting one of the following:\n\n   := . ( @ % ;\nThe symbol ";" was substituted for "END" to continue.\n')]

我们正在研究 cx_Oracle 的 future 版本如何直接公开 Oracle 的“成功信息”标志和编译错误消息。

关于python - 如何从 Python 脚本中创建存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64000401/

相关文章:

python - Django 。如何在用户模型中添加额外字段并将其显示在管理界面中

Python Asyncio 未使用 asyncio.run_coroutine_threadsafe 运行新协程

oracle - oracle中的序列创建

c# - ADO.NET 提供程序 'Oracle.ManagedDataAccess.Client' 未在机器或应用程序配置文件中注册,或者无法加载

mysql - 获取一些行和总数的存储过程

Python 使用错误的包版本

python - 使用 Python 转换二进制文件(Labview .DAT 文件)

java - 从 Hibernate 同时执行插入和选择查询

sql-server - 从存储过程中检索服务器名称和数据库名称

sql-server - 使用存储过程进行计算