【发布时间】:2021-12-12 23:48:53
【问题描述】:
我正在使用 teradatasql python 模块,我无法在documentation 中找到如何将命名参数传递到 cursor.execute()
我有采用IN 参数的存储过程,但在 teradatasql 中我看不到传递列名的选项。有没有办法做到这一点?
这是我的 PROC 的一些 sn-p,它采用 IN 参数
(
IN transId VARCHAR(50),
IN name VARCHAR(50),
IN add VARCHAR(50),
IN zip VARCHAR(50),
IN area VARCHAR(50)
)
代码
with teradatasql.connect ('{"host":"whomooz","user":"guest","password":"please"}') as con:
with con.cursor () as cur:
cur_execute (cur, "{call examplestoredproc (?, ?)}", [10, 7]) # bound parameter values
def cur_execute (cur, sSQL, params=None):
print ()
print ("cur.execute", sSQL, "bound values", params)
cur.execute (sSQL, params)
【问题讨论】:
-
没有错误信息?如果你真的想传递一个列名,你需要在你的SP中切换到动态SQL
-
@dnoeth 是的,没有错误消息只返回零记录。所以没有其他方法可以使用
teradatasql传递列名? -
你想用“列名”做什么?显示你的过程的相关位。您显示的参数中没有任何内容与此相关。
-
仅位置参数 - 由 ? 指示- 在请求中支持,而不是像
zip='12345'这样的命名参数。如果您只想传递第二个和第四个参数的值而不需要占位符 - 在 Python 端可能是None。 -
@Fred,所以通过查看我在帖子中的存储过程示例。这是我的请求是如何进行的
cur.execute {call examplestoredproc (?,?, ?, ?, ?,?,?)} bound values ['1233', '2222', 'Test', 'Test1', None, 'I', 'test2'].. 以及它返回的零记录.. 我如何确保每个值都与我的存储过程匹配?
标签: python python-3.x teradata teradatasql