1. 程式人生 > >【我的Android進階之旅】如果使用.output命令將SQLite資料庫中的資料匯出為文字?

【我的Android進階之旅】如果使用.output命令將SQLite資料庫中的資料匯出為文字?

一、需求描述

最近在做一個漢字筆畫排序的功能,正好整理好了一個數據庫,現在想把這個資料庫內容匯出來為文字內容。

二、匯出資料庫內容

現在準備將這個ChinessStroke.db匯出來,步驟如下

在這裡插入圖片描述

D:\>sqlite3 ChinessStroke.db
SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
sqlite> .output ChinessStroke.dat
sqlite> select * from BI_HUA_BEAN;
sqlite> .output stdout
sqlite>

1、先用sqlite3命令開啟ChinessStroke.db資料庫

sqlite3 ChinessStroke.db
SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.

2、使用 .output ChinessStroke.dat – 所有輸出寫入 ChinessStroke.dat檔案

sqlite> .output ChinessStroke.dat

3、輸入查詢語句查詢表格內容,查詢出要導的資料. 查詢後,資料不會顯示在螢幕上,而直接寫入檔案.

sqlite> select * from BI_HUA_BEAN;

4、使用.output stdout – 切換回預設值,將輸出重定向至螢幕.

sqlite> .output stdout

這樣就將 ChinessStroke.db 到處為了ChinessStroke.dat檔案。
在這裡插入圖片描述

內容如下所示:
在這裡插入圖片描述

匯出來的ChinessStroke.dat檔案下載地址為: