1. 程式人生 > >SQLite相關知識及語句

SQLite相關知識及語句

一.sqlite 知識點

1.sqlite管理工具

ubuntu:sqlite database browser    windows:sqlite3

二.常用sqlite語句

1.查詢person表第10~20條資料

select × from person limit 9, 11  (9表開始位置,11表示連續查詢的條數);

2.插入或修改person表某條記錄(主鍵存在則修改,不存在則插入)

replace into person (id,name,age) values (2,'zhaoyun',18);

3.複製person表資料到teacher表

create table  teacher  as select * from  person;

4.根據person內容建立檢視people

create view if not exists  people as select × from person;

三.常用sqlite 函式

1.取絕對值    abs(x)

2.查詢最近一次sqlite語句影響的行數    select changes();

3.查詢某行第一個不為null的值 select  coalesce (name,age) as value from person;(ifnull 只支援兩個引數)

4.like語句  select  × from person where  name like  '%zhaoyun%';

5.擷取字串:

select substr("abcdef",2)   結果bcdef  

select substr("abcdef",2,3)   結果bcd

6.查詢當前欄位資料型別  select  typeof(name) from person;

7.日期函式:

1).select date('2016-06-06','-1 year','+1 month') 輸出 2015-07-06

2).select date('now','start of month','+1 month','-1 day') 輸出 2017-02-28;(now 2017-02-10)