【问题标题】:Mysql-Python-Connector get columns names from select statement in stored procedureMysql-Python-Connector 从存储过程中的 select 语句中获取列名
【发布时间】:2016-03-05 22:38:30
【问题描述】:

我有一个包含多个简化如下语句的存储过程

create temp table...; 
update temp table...; 
....
select * from temp table; #last statement

我有以下 Python 代码可以从 SP 获取返回结果。我需要列名,以便可以将结果转换为 JSON 格式。但是, cursor.description 没有返回任何我期望的结果。请指教!! Mysql5.7,Oracle 的 mysql-python-connector 2.x,python 3.5

cursor.callproc(proc, args)
columns = cursor.description
print(columns) #returns [('@_sp_get_toc_arg1', 8, None, None, None, None, 1, 128)]

for result in cursor.stored_results():
    return result.fetchall()

【问题讨论】:

    标签: mysql mysql-python


    【解决方案1】:

    cursor.stored_results() 返回的迭代器产生游标,您需要检查这些描述以获取列名,而不是初始游标:

    for result in cursor.stored_results():
        print(result.description)
        return result.fetchall()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 2020-02-28
      相关资源
      最近更新 更多