3

できれば周辺ソフトウェアを使用せずに、固定幅のテキスト ファイルを 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

この線

AABCDEFGHIJABCDEAABCDEFGA

次のようにインポートされます。

Field 1     Field 2  Field 3
ABCDEFGHIJ  ABCDE    ABCDEFG

ありがとう

4

2 に答える 2

8

The link in the answer above is for generic SQL. Here is one way to do it in 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
于 2014-09-27T19:45:08.327 に答える
1

ツールはsqlite3CSVファイルのみをインポートします。

固定幅のファイルをインポートできるサードパーティのツールがありますが、この回答は、文字列関数を使用してSQLite内でこれを行う方法を示しています。

于 2012-09-14T12:34:04.657 に答える