使用scriptella导入fixwidth文本文件

时间:2013-03-11 14:31:37

标签: scriptella

使用scriptella将fixwidth文件导入表的最佳方法是什么?

TEXTFILE:

blabla bloblo ble    bli

columnWidth时:

(1,7) (8,14) (15,21) (22,24)

表:

T_IMPORT (
  FIELD1 VARCHAR(8),
  FIELD2 VARCHAR(8),
  FIELD3 VARCHAR(8),
  FIELD4 VARCHAR(4)
)

1 个答案:

答案 0 :(得分:0)

我提出的解决方案是:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
    <connection id="database" url="jdbc:hsqldb:mem:mymemdb" user="SA" password=""/>
    <connection id="in" driver="text" url="${filePath}test_import.txt" />
    <query connection-id="in">
            <script connection-id="database">
                INSERT INTO T_IMPORT 
                VALUES (
                ?{column0.substring(0,7)},
                ?{column0.substring(8,14)},
                ?{column0.substring(15,21)},
                ?{column0.substring(22,24)});
        </script>
    </query>
</etl>