Pypyodbc:在存储过程保存在选项卡中的循环中执行存储过程

2024-10-04 01:32:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个表,其中的数据如下所示

Name  Query   RunDate
SP    Some_sp 12/25/2017
Sp1   Some1_sp 12/25/2017
sp_2  Some2_sp 12/25/2107

查询列具有要执行的存储过程。在

^{pr2}$

我正在查询该表并将其保存为pandas dateframe。下一步是逐个执行查询列中的存储过程。有没有一种方法可以使用pypyodbc实现这一点?在


Tags: 数据方法namepandas过程somequerysp
1条回答
网友
1楼 · 发布于 2024-10-04 01:32:35

试试这个:

def getDatafromDB(self):
    sql = """Select Query from table"""
    self.cursor.execute(sql)
    data=self.cursor.fetchall()
    while data:
         print(data)
         if self.cursor.nextset():
             sql = "{call "+data+"(?)}"
             params = (3,)
             cursor = connection.cursor()
             rows = cursor.execute(sql, params).fetchall()
             print(rows)
         else:
             data= None

相关问题 更多 >