您可以考虑在临时表中进行初步导入,根据行的类型(页眉、type1 子、type2 子或页脚),您填充两个新列RECORD_ID
和ROW_TYPE
.
RECORD_ID
将通过序列填充,nextVal()
在行类型为标题时使用,lastVal()
在其他情况下使用。
ROW_TYPE
将填充行类型。
通过这种方式,您以后可以根据 的值填充您的表,并在列ROW_TYPE
中保留父子之间的关系。RECORD_ID
编辑(进一步解释)
假设您的文件行具有以下结构
Header: Field1;Field2;Field3
Type1: Field1;Field2
Type2: Field1;Field2;Field3;Field4
Footer: Field1;Field2
然后,您的目标表将需要相应文件行中的每个字段的列,加上 ID 列。他们看起来像这样
Header
ID | Header col1 | Header col2 | Header col3
Type1
ID | Type1 col1 | Type1 col2
Type2
ID | Type2 col1 | Type2 col2 | Type2 col3 | Type2 col4
Footer
ID | Footer col1 | Footer col2
然后你的临时表将有 6 列(5 列来自有更多的表,加上 1 列Type
)并且看起来像这样
Temp
Type | ID | Temp col1 | Temp col2 | Temp col3 | Temp col4
使用这种结构,您可以拥有第一个接口,该接口加载表中文件的每一行,Type
根据您正在分析的行在列中放入不同的值,并正确调用列中的序列(nextVal()
或lastVal()
)ID
.
Temp interface
Type <- rowType
ID <- case when rowType = Header then sequence.nextVal() else sequence.lastVal() end
Temp col1 <- File field1
Temp col2 <- File field2
Temp col3 <- File field3
Temp col4 <- File field4
然后,您可以有多个接口,从这个临时表中,每个接口将填充一个目标表,在 Type 列上进行过滤。
Header interface
ID <- ID
Header col1 <- Temp col1
Header col2 <- Temp col2
Header col3 <- Temp col3
where Type = 'Header'