简体   繁体   English

在pymssql中使用`query`和`callproc`调用存储过程的区别

[英]Difference between calling stored procedure with `query` and `callproc` in pymssql

I have a stored procedure saved on SQL Server and using pymssql to connect to that database.我在 SQL Server 上保存了一个存储过程,并使用 pymssql 连接到该数据库。

I can call this procedure by calling cursor.query('EXEC FindPerson') successfully.我可以通过成功调用cursor.query('EXEC FindPerson')来调用这个过程。 But I can't use the method cursor.callproc('FindPerson', (name,)) , I got this error但是我不能使用方法cursor.callproc('FindPerson', (name,)) ,我收到了这个错误

'<' not supported between instances of 'NoneType' and 'int' “NoneType”和“int”的实例之间不支持“<”

I wonder why I can't call callproc method.我想知道为什么我不能调用callproc方法。 The reason I want to use callproc is to be able to loop different result sets from the procedure.我想使用callproc的原因是能够从过程中循环不同的结果集。

I also tried to put different stored procedure on this method, regardless what is the parameter I put into, I always got the same error.我也尝试在这个方法上放不同的存储过程,不管我放了什么参数,我总是得到同样的错误。 So it seems that the method callproc failed even before hitting the procedure.所以看起来方法callproc甚至在点击过程之前就失败了。 The question is what the correct way to call a stored procedure?问题是调用存储过程的正确方法是什么?

Below is an example of stored procedure.下面是一个存储过程的例子。

CREATE PROCEDURE FindPerson
    @name VARCHAR(100)
AS 
BEGIN
    SELECT * 
    FROM persons 
    WHERE name = @name
END

You need to pass name param in tuple.您需要在元组中传递名称参数。 Try cursor.callproc('FindPerson', (personname,))试试 cursor.callproc('FindPerson', (personname,))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM