sqlite的csv的导⼊,导出草莓的英文怎么写
-----------------------------------以下这段,是⼗分容易百度到的,但它不是csv的导⼊导出的适⽤⽅法,更适合格式化输出,说⽩了就是⽅便⼈看,它会给长⽂本的字段数据添加空格和适当截断。这些对于需要后续程序处理的导出操作是致命的。
导⼊
命令: .import
sqlite> .import ⽂件名表名
注1: 不要忘了开头的点
注2: 这条语句不能⽤分号结束. ⾮SQL不需要分号结束.
注3: 需要查看默认的分隔符parator. 必须⼀致. 如果不⼀致可能导致sqlite字段分割错误.
查看分隔符使⽤命令 .show , 如果不⼀致可直接修改, ⽐如:
sqlite>.parator ","
将分隔符转为逗号.
发现外星人举例1:
将⽂件a.txt中的数据导⼊表 tab_xx. (a.csv中字段以逗号分割)
sqlite> .parator ","
sqlite> . tab_xx
sqlite>
导⼊结束.
导出
实现⽅式: 将输出重定向⾄⽂件.
命令: .output
sqlite> .
然后输⼊sql语句, 查询出要导的数据. 查询后,数据不会显⽰在屏幕上,⽽直接写⼊⽂件.
结束后,输⼊
sqlite> .output stdout
最美的季节
将输出重定向⾄屏幕.
举例2:侮辱罪的立案标准
将 tab_xx 中的数据导出到⽂件a.txt
sqlite> .
sqlite> lect * from tab_xx;
sqlite> .output stdout
dnf气功
导出完毕.
抗病毒颗粒说明书
如需导成csv格式,直接将⽂件a.txt换成a.csv即可
-
----------------------------------根据官⽹的documents 应该⽤以下⽅法
CSV Import
U the ".import" command to import CSV (comma parated value) data into an SQLite table. The ".import" command takes two arguments which are the name of the disk file from which CSV data is to be read and the name of the SQLite table into which the CSV data is to be inrted.
Note that it is important to t the "mode" to "csv" before running the ".import" command. This is necessary to prevent the command-line shell from trying to interpret the input file text as some other format.
sqlite> .mode csv
sqlite> .import C:/work/somedata.csv tab1
There are two cas to consider: (1) Table "tab1" does not previously exist and (2) table "tab1" does already exist.
In the first ca, when the table does not previously exist, the table is automatically created and the
content of the first row of the input CSV file is ud to determine the name of all the columns in the table. In other words, if the table does not previously exist, the first row of the CSV file is interpreted to be column names and the actual data starts on the cond row of the CSV file.
For the cond ca, when the table already exists, every row of the CSV file, including the first row, is assumed to be actual content. If the CSV file contains an initial row of column labels, that row will be read as data and inrted into the table. To avoid this, make sure that table does not previously exist.
CSV Export
To export an SQLite table (or part of a table) as CSV, simply t the "mode" to "csv" and then run a query to extract the desired rows of the table.
sqlite> .header on脚英语
sqlite> .mode csv
sqlite> .once c:/work/dataout.csv
sqlite> SELECT * FROM tab1;
sqlite> .system c:/work/dataout.csv
In the example above, the ".header on" line caus column labels to be printed as the first row of output. This means that the first row of the resulting CSV file will contain column labels. If column labels are not desired, t ".header off" instead. (The ".header off" tting is the default and can be omitted if the headers have not been previously turned on.)
The line ".once FILENAME" caus all query output to go into the named file instead of being printed on the console. In the example above, that line caus the CSV content to be written into a file named "C:/work/dataout.csv".天蝎座双鱼座
The final line of the example (the ".system c:/work/dataout.csv") has the same effect as double-clicking on the c:/work/dataout.csv file in windows. This will typically bring up a spreadsheet program to display the CSV file. That command only works as shown on Windows. The equivalent line on a Mac would be ".system open /work/dataout.csv". On Linux and other unix systems you will need to enter something like ".system libreoffice /work/dataout.csv", substituting your preferred CSV viewing program for "libreoffice".