加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLite3 模糊查询

发布时间:2020-12-12 20:31:59 所属栏目:百科 来源:网络整理
导读:如果你还没有安装或者使用过 sqlite,可以借助SQLite3 安装、基本操作入门。 1. 创建数据库 test.db cd ~/ sqlite3 test.db 这样在 ~/ 目录下面就生成一个数据库文件test.db. 2. 创建表 song create table if not exists song (path TEXT,title varchar(20))

如果你还没有安装或者使用过 sqlite,可以借助SQLite3 安装、基本操作入门。


1. 创建数据库 test.db


cd ~/

sqlite3 test.db


这样在 ~/ 目录下面就生成一个数据库文件test.db.


2. 创建表 song


create table if not exists song (path TEXT,title varchar(20));


创建一个名称为 song 的数据库表,包含 path、title 两个字段,类型分别是 Text、varchar.


3. 插入数据


insert into song values('/mnt/sdcard/music','only you');


insert into song values('/mnt/sdcard/music','love');


insert into song values('/exte/music','thinking');


共插入 3 条数据。


这个时候,验证一下,数据库表中的数据。查询:


select * from song;




4. 查询指定条件的数据


select * from song where path='/mnt/sdcard/music'


或者


select * from song where path="/mnt/sdcard/music"




现在有个需求,查出所有 / 目录下面的歌曲信息?


当然是模糊查询!


select * from song where path LIKE '/%';


或者


select * from song where path LIKE "/%";


轻松搞定!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读