学习笔记(25):21天通关Python(仅视频课)-执行查询

立即学习:https://edu.csdn.net/course/play/24797/282205?utm_source=blogtoedu

import sqlite3

conn = sqlite3.connect('test52.db')
c = conn.cursor()
# 执行查询语句
c.execute('select * from user_tb')
# description属性(元组)返回类信息
for col in c.description:
    print(col[0], end='\t')
print()

# fetchall() 返回所有数据,大数据量不介意使用
# for val in c.fetchall():
#     print(val)

# fetchone() 返回一行数据
# while True:
#     row = c.fetchone()
#     if row:
#         for val in row:
#             print(val, end='\t')
#         print()
#     else:
#         break
# fetchmany(n)  n小于列表数量
# for val in c.fetchmany(2):
#     print(val)

for val in c:
    print(val)
c.close()
conn.close()
发布了39 篇原创文章 · 获赞 29 · 访问量 902

猜你喜欢

转载自blog.csdn.net/happyk213/article/details/105232322
今日推荐