我正在寻找在 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/