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

How can I create stored procedure from within Python script?

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

我知道,cursor.callproc in cx_Oracle 存在调用现有的存储过程,但我正在寻找一个 way/method 来创建Python.

中的 Oracle 存储过程

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

要检查该程序是否有效,您需要查询一个碱基 table,例如 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 的未来版本如何直接公开 Oracle 的 'success with info' 标志和编译错误消息。