Execute a PL/SQL function (or procedure) from SQLAlchemy

后端 未结 2 408
野性不改
野性不改 2021-01-22 10:19

I have a legacy PL/SQL function:

getlogin(p_username in varchar2, p_password in varchar2) return boolean;

How can I execute this from SQLAlchem

相关标签:
2条回答
  • 2021-01-22 10:33

    You'll probably have to provide a PL/SQL block to your execute call:

    result = DBSession.execute('begin getlogin(:username, :password); end;',
                                 {'username':request.POST['username'],'password':request.POST['password']});
    

    This SO question on SQLAlchemy + Oracle SP might also help.

    0 讨论(0)
  • 2021-01-22 10:51

    If you're using .execute() on a connection method then you need a valid SQL statement. If getlogin is a function, this requires a SELECT:

    result = DBSession.execute('select getlogin(:username, :password) from dual'
                              , {'username' : request.POST['username']
                                 ,'password' : request.POST['password']});
    

    As the error states, your SQL statement is invalid.

    0 讨论(0)
提交回复
热议问题