Python: Execute Stored Procedure with Parameters

后端 未结 3 1205
悲&欢浪女
悲&欢浪女 2020-12-21 15:01

I\'m working on a Python script that writes records from a stored procedure to a text file. I\'m having issues executing the stored procedure with parameters.

I\'m n

相关标签:
3条回答
  • 2020-12-21 15:21

    I was able to fix the syntax error by removing the parenthesis from the query string.

    # Execute stored procedure
    storedProc = "exec database..stored_procedure('param1', 'param2')"
    

    should be

    # Execute stored procedure
    storedProc = "exec database..stored_procedure 'param1','param2'"
    
    0 讨论(0)
  • 2020-12-21 15:22

    This worked for me

    query = "EXEC [store_proc_name] @param1='param1', @param2= 'param2'"
    cursor.execute(query)
    
    0 讨论(0)
  • 2020-12-21 15:31

    For SQL Server:

    cursor.execute('{call your_sp (?)}',var_name)
    
    0 讨论(0)
提交回复
热议问题