Reputation: 63
I am looking to way to create an oracle stored procedure in Python.
I know, cursor.callproc
in cx_Oracle exists to call the existing stored procedure, but I am looking for a way/method to create an Oracle stored procedure in Python.
Upvotes: 2
Views: 3190
Reputation: 10506
Just use execute()
with the SQL CREATE OR REPLACE
command.
To check if the procedure was valid, you need to query a base table like 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)
The output is:
[('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')]
We are looking at how a future version of cx_Oracle can directly expose Oracle's 'success with info' flag and the compilation error message.
Upvotes: 3