简体   繁体   English

在单独的行上打印 SQL 查询 output

[英]Printing SQL query output on separate lines

I need to print the result of my SQL query on separate lines as currently it returns as one big long line as shown below.我需要在单独的行上打印我的 SQL 查询的结果,因为目前它返回为一大长行,如下所示。

在此处输入图像描述 在此处输入图像描述

here is the code so far这是到目前为止的代码

def getdata(name):
    conn = sqlite3.connect('details.db')
    c = conn.cursor()
    c.execute("SELECT * FROM tbldetails WHERE name = '" + name +"' ")
    result = c.fetchone()
    return(result)

The result I am looking for is the outputs to be as follows:我正在寻找的结果是输出如下:

value1
value2
value3

you should share the value of the cell that you're fetching to provide more information.您应该共享要获取的单元格的值以提供更多信息。

Generally you could either:通常,您可以:

  1. .split() the value on any separator-character. .split()任何分隔符上的值。
  2. Iterate over the result with for x in c.execute(... for x in c.execute(...
  3. Or maybe even use c.fetchall() and iterate over the list.或者甚至可以使用c.fetchall()并遍历列表。

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

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