nac*_*dus 2 sqlite text fixed-width
将固定宽度的文本文件导入sqlite表的好方法是什么,最好不使用外围软件?
例如,指定每个字段的宽度
Field 1: 10 characters starting with the second character
Field 2: 5 characters starting with the twelfth character
Field 3: 7 characters starting with the eighteenth character
Run Code Online (Sandbox Code Playgroud)
这条线
AABCDEFGHIJABCDEAABCDEFGA
Run Code Online (Sandbox Code Playgroud)
将被导入为:
Field 1 Field 2 Field 3
ABCDEFGHIJ ABCDE ABCDEFG
Run Code Online (Sandbox Code Playgroud)
谢谢
小智 6
上面答案中的链接用于通用SQL.这是在SQLite中执行此操作的一种方法:
CREATE TABLE fixed_width_table (full_string CHAR);
.import fixed_width_file.txt fixed_width_table
CREATE TABLE tmp AS
Select
SUBSTR(full_string,1,11) AS field1
,SUBSTR(full_string,2,5) AS field2
,SUBSTR(full_string,2,7) AS field3
FROM fixed_width_table
Run Code Online (Sandbox Code Playgroud)