SQLite3 模糊查詢

來源:互聯網
上載者:User

如果你還沒有安裝或者使用過 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  "/%";


輕鬆搞定!




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.