Django 用户认证 用户 邮箱登录 邮箱注册 ORM or,and,not form.py FORM ModelForm Paginator 分页 HTMl JQuery 定位元素 ajax django切片 restfulapi 跨域 Ubantu Python Mysql Scrapy 爬虫 导出 Python读写 Pycharm 破解 session re sqlit3 生成式 其他 Prism 富文本 CSS Nginx 部署 请求头 抓包 协议 selenium Ubuntu 宝塔 AI Comfy-ui ollama dify open-webui Git docker
sqlite3数据匹配
张建行 2019年3月19日 05:31 34 文章标签: sqlit3

# %a%:匹配数据中心包含a字符的数据
# like:主要用于匹配数据库中的多条记录
# a_:匹配以a开头,并且只匹配a最后一个字符的数据。
# %a:匹配以a结尾的数据
# a%:匹配以a开头的数据
# %a%:匹配数据中心包含a字符的数据
import sqlite3
# 1. 创建数据库连接
connect = sqlite3.connect('sqltest.db')
# 2. 使用连接创建游标
cursor = connect.cursor()
# 查找student表中age大于22的数据
sq = "select * from student where age >22"
# 查找student表中name=‘王思聪’的数据
sql_4 = "select * from student where name='王思聪'"
# 查找student表中name以‘三’结尾的数据
sql_1 = "select * from student where name like '%三'"
# 查找student表中name以‘王’开头的数据
sql_2 = "select * from student where name like  '王%'"
# 查找student表中name中间包含‘思’的数据
sql_3 = "select * from student where name like '%思%'"
result = cursor.execute(sql_4)
for id,name,age,score in result:
   print(id,name,age,score)
# 提交操作
connect.commit()
# 关闭游标
cursor.close()
# 关闭数据库连接
connect.close()