简体   繁体   中英

parsing oracle 11g

I have the following snippet of a file that needs parsing :

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

The respective positions for the string are as follows:

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

I need to parse the string to extract these records from that string. Can anyone help with the substr/instr functionality to account for the string and blank spaces. The extracted data would then get inserted into a table. Thank you in advance!

Can you not simply use a sqlloader control file eg

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 ")"

You don't need instr, because the position is already specified. Instead use substr

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM