解析oracle 11g

时间:2015-05-13 14:07:13

标签: sql oracle plsql oracle11g

我有一个需要解析的文件片段:

000000837002100302015-04-13-15.55.12.1922082015-04-1300032128CHECK CLEARED CHECK CLEARED 00000000000030000000000000000000000000000000016594703

字符串的各个位置如下:

RECORD1                     - POS (1  :10 ) - DUR 10
RECORD2                     - POS (11 :13 ) - DUR 3
RECORD3                     - POS (14 :17 ) - DUR 4
RECORD4                     - POS (18 :43 ) - DUR 26
RECORD5                     - POS (44 :53 ) - DUR 10
RECORD6                     - POS (54 :61 ) - DUR 8
RECORD7                     - POS (62 :95 ) - DUR 34
RECORD9                     - POS (96 :215) - DUR 120
RECORD10                    - POS (216:233) - DUR 18
RECORD11                    - POS (234:251) - DUR 18
RECORD12                    - POS (252:266) - DUR 15
RECORD13                    - POS (267:268) - DUR 2

我需要解析字符串以从该字符串中提取这些记录。任何人都可以帮助substr / instr功能来解释字符串和空格。然后将提取的数据插入表中。提前谢谢!

2 个答案:

答案 0 :(得分:1)

你能不能简单地使用sqlloader控制文件,例如

echo "OPTIONS (DIRECT=TRUE)"
echo "LOAD DATA"
echo "INFILE '/path/to/file/$1'"
echo "BADFILE '/path/to/file/log/$1.bad'"
echo "DISCARDFILE '/path/to/file/log/$1.dsc'"
echo "APPEND INTO TABLE table.t"
echo "("
echo "    RECORD1      POSITION (1:10),"
echo "    RECORD2   POSITION (11:13),"
etc...
echo ")"

答案 1 :(得分:0)

您不需要instr,因为已经指定了位置。代替 使用substr

insert into some_table 
select substr(text, 1, 10) rec1, substr(text, 11, 3) rec2, ... 
from text_table;