我有一个遗留的PL / SQL函数:
getlogin(p_username in varchar2, p_password in varchar2) return boolean;
如何从SQLAlchemy执行此操作并获取返回值?
这样的幼稚方法似乎不起作用:
result = DBSession.execute('getlogin(:username, :password)',
{'username':request.POST['username'],'password':request.POST['password']});
# extract return value from result
从日志中,我看到此错误:
File “../env/lib/python3.3/site-packages/SQLAlchemy-0.8.0-py3.3.egg/sqlalchemy/engine/base.py”, line 871, in _execute_context
context)
File “../env/lib/python3.3/site-packages/SQLAlchemy-0.8.0-py3.3.egg/sqlalchemy/engine/default.py”, line 322, in do_execute
cursor.execute(statement, parameters)
cx_Oracle.DatabaseError: ORA-00900: invalid SQL statement
我可以看到它看起来像正在调用SQL解释器,而不是PL / SQL解释器,但是我不确定下一步如何.
解决方法:
您可能必须为执行调用提供一个PL / SQL块:
result = DBSession.execute('begin getlogin(:username, :password); end;',
{'username':request.POST['username'],'password':request.POST['password']});
SQLAlchemy Oracle SP上的This SO question也可能会有所帮助.