• <bdo id='Xe948'></bdo><ul id='Xe948'></ul>
    <i id='Xe948'><tr id='Xe948'><dt id='Xe948'><q id='Xe948'><span id='Xe948'><b id='Xe948'><form id='Xe948'><ins id='Xe948'></ins><ul id='Xe948'></ul><sub id='Xe948'></sub></form><legend id='Xe948'></legend><bdo id='Xe948'><pre id='Xe948'><center id='Xe948'></center></pre></bdo></b><th id='Xe948'></th></span></q></dt></tr></i><div id='Xe948'><tfoot id='Xe948'></tfoot><dl id='Xe948'><fieldset id='Xe948'></fieldset></dl></div>

    <tfoot id='Xe948'></tfoot>

      1. <legend id='Xe948'><style id='Xe948'><dir id='Xe948'><q id='Xe948'></q></dir></style></legend>
      2. <small id='Xe948'></small><noframes id='Xe948'>

      3. Python - pyodbc 调用带有参数名称的存储过程

        Python - pyodbc call stored procedure with parameter name(Python - pyodbc 调用带有参数名称的存储过程)
        <i id='Zq4ai'><tr id='Zq4ai'><dt id='Zq4ai'><q id='Zq4ai'><span id='Zq4ai'><b id='Zq4ai'><form id='Zq4ai'><ins id='Zq4ai'></ins><ul id='Zq4ai'></ul><sub id='Zq4ai'></sub></form><legend id='Zq4ai'></legend><bdo id='Zq4ai'><pre id='Zq4ai'><center id='Zq4ai'></center></pre></bdo></b><th id='Zq4ai'></th></span></q></dt></tr></i><div id='Zq4ai'><tfoot id='Zq4ai'></tfoot><dl id='Zq4ai'><fieldset id='Zq4ai'></fieldset></dl></div>
        <tfoot id='Zq4ai'></tfoot>
            <tbody id='Zq4ai'></tbody>

              <bdo id='Zq4ai'></bdo><ul id='Zq4ai'></ul>

              <legend id='Zq4ai'><style id='Zq4ai'><dir id='Zq4ai'><q id='Zq4ai'></q></dir></style></legend>
            • <small id='Zq4ai'></small><noframes id='Zq4ai'>

                • 本文介绍了Python - pyodbc 调用带有参数名称的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要使用输入参数名称通过pyodbc模块从python2.7调用SqlServer存储过程.

                  I need to call a SqlServer stored procedure from python2.7 via pyodbc module with input parameter name.

                  我根据输入参数顺序尝试基于 文档:

                  I tried based on documentation by input parameter order:

                  cursor.execute('{CALL [SP_NAME](?,?)}',
                                ('value', 'value'))
                  

                  它有效,但我需要传递存储过程的参数名称,因为存储过程输入参数的顺序总是在变化.所以我需要按名称传递它们.

                  It works, but I need to pass parameter name of stored procedure because order of stored procedure input parameter always changes. So I need to pass them by name.

                  cursor.execute('{CALL [SP_NAME](@param1name,@param2name)}',
                                ('value', 'value'))
                  

                  然而这行不通.正确的语法是什么?

                  However this doesn't work. What's the correct syntax?

                  推荐答案

                  我在 SQL Server 2008 R2 中使用以下存储过程对此进行了测试:

                  I tested this using the following stored procedure in SQL Server 2008 R2:

                  CREATE PROCEDURE [dbo].[breakfast] 
                      @person varchar(50) = 'nobody', 
                      @food varchar(50) = 'tofu'
                  AS
                  BEGIN
                      SET NOCOUNT ON;
                      SELECT @person + ' likes to eat ' + @food
                  END
                  

                  坏消息(CALL")

                  我发现

                  sql = """
                  { CALL breakfast (@food=?, @person=?) }
                  """
                  params = ('bacon','Gord')
                  crsr.execute(sql, params)
                  

                  给出不一致的结果.

                  使用 {SQL Server Native Client 10.0} ODBC 驱动程序,它忽略参数 names 并将参数视为位置参数,产生 ...

                  With the {SQL Server Native Client 10.0} ODBC driver it ignored the parameter names and treated the parameters as positional, yielding ...

                  bacon likes to eat Gord
                  

                  ... 使用旧的 {SQL Server} ODBC 驱动程序,我刚刚收到错误

                  ... and with the older {SQL Server} ODBC driver I just got the error

                  DataError: ('22018', '[22018] [Microsoft][ODBC SQL Server Driver]转换规范的字符值无效 (0) (SQLExecDirectW)')

                  DataError: ('22018', '[22018] [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification (0) (SQLExecDirectW)')

                  好消息(EXEC")

                  我发现了

                  sql = """
                  EXEC breakfast @food=?, @person=?
                  """
                  params = ('bacon','Gord')
                  crsr.execute(sql, params)
                  

                  使用两个 ODBC 驱动程序给了我以下(正确的)结果

                  gave me the following (correct) result using both ODBC drivers

                  Gord likes to eat bacon
                  

                  这篇关于Python - pyodbc 调用带有参数名称的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  How to find a text inside SQL Server procedures / triggers?(如何在 SQL Server 程序/触发器中查找文本?)
                  SQL Server stored procedure return code oddity(SQL Server 存储过程返回码奇怪)
                  Conditional SQL ORDER BY ASC/DESC for alpha columns(alpha 列的条件 SQL ORDER BY ASC/DESC)
                  Export stored procedure result set to Excel in SSMS(在SSMS中将存储过程结果集导出到Excel)

                  <small id='PrFes'></small><noframes id='PrFes'>

                    <tbody id='PrFes'></tbody>

                  • <i id='PrFes'><tr id='PrFes'><dt id='PrFes'><q id='PrFes'><span id='PrFes'><b id='PrFes'><form id='PrFes'><ins id='PrFes'></ins><ul id='PrFes'></ul><sub id='PrFes'></sub></form><legend id='PrFes'></legend><bdo id='PrFes'><pre id='PrFes'><center id='PrFes'></center></pre></bdo></b><th id='PrFes'></th></span></q></dt></tr></i><div id='PrFes'><tfoot id='PrFes'></tfoot><dl id='PrFes'><fieldset id='PrFes'></fieldset></dl></div>
                      <bdo id='PrFes'></bdo><ul id='PrFes'></ul>

                        <tfoot id='PrFes'></tfoot>

                            <legend id='PrFes'><style id='PrFes'><dir id='PrFes'><q id='PrFes'></q></dir></style></legend>