Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parsing an EDI file and populating the data into database table

1059338Dec 9 2013 — edited Dec 9 2013

Hi ,

Please help me in parsing an edi file and getting the required columns.

we get an EDI file from a bank. I need to parse that file and populate the db table with the required columns.

the file is '*' delimited and every line ends with '\'.

The record starts with 'ST*' and ends with 'SE*'.

sample edi file is

ISA*00*          *00*          *ZZ*043000096820   *ZZ*2156833510     *131202*0710*U*00401*000001204*0*P*>\  ignore first 2 lines                                                                                                                                                                                              

GS*RA*043000096820*2156833510*131202*0710*1204*X*003020\                                                                                                                                                                                                                                                  

ST*820*000041031\                                                                                                                                                                                                                                                                                     

BPR*X*270*C*ACH*PPD*01*101036669***9101036669**01*031000053*DA*00000008606086714*131202\                                                                                                                                                                                                                  

TRN*1*101036661273032\                                                                                                                                                                                                                                                                                    

DTM*007*131202\                                                                                                                                                                                                                                                                                           

N1*1U*BPS\                                                                                                                                                                                                                                                                             

N1*BE*MICHAEL    DRAYTON*34*159783633\                                                                                                                                                                                                                                                                    

N1*PE*BPS*ZZ*183383689C2 ABC\                                                                                                                                                                                                                                                          

N1*PR*ABC  TREAS 310\                                                                                                                                                                                                                                                                                     

SE*9*000041031\ ST*820*000041032\                                                                                                                                                                                                                                                                                         

BPR*X*686*C*ACH*PPD*01*101036669***9101036669**01*031000053*DA*00000008606086714*131202\                                                                                                                                                                                                                  

TRN*1*101036661273034\                                                                                                                                                                                                                                                                                    

DTM*007*131202\                                                                                                                                                                                                                                                                                           

N1*1U*BPS\                                                                                                                                                                                                                                                                             

N1*BE*SAMIA      GRAVES*34*892909238\                                                                                                                                                                                                                                                                     

N1*PE*BPS*ZZ*184545710C5 ABC\                                                                                                                                                                                                                                                          

N1*PR*ABC  TREAS 310\                                                                                                                                                                                                                                                                                     

SE*9*000041032\

Below is the procedure I am trying to use for parsing that file. but the logic is not working. can you please help me in doing this. its very urgent requirement.

CREATE OR REPLACE package body p1 is

-----------------------------------------------------------------------------
Function parse_spec(p_str varchar2) return t_str_nt is
begin
      return regexp_replace(p_str,'\\$',null);
end;

-----------------------------------------------------------------------------
procedure edi( is
l_out_file              utl_file.file_type;
l_lin                 varchar2(200);
field1            number(9);
field2                varchar2(10 byte);
field3           varchar2(15 byte);
field4               varchar2(15 byte);
field5              varchar2(20 byte);
field6             varchar2(20 byte);
field7              varchar2(20 byte);
field8                  varchar2(9 byte);
field9              varchar2(15 byte);
field10             varchar2(5 byte);
l_item_nt             t_str_nt:=t_str_nt();

begin

   l_out_file  := utl_file.fopen (file_path, file_name, 'r');
   IF utl_file.is_open(l_out_file) THEN
    LOOP
      BEGIN
       l_item_nt:= utl_file.get_line(l_out_file, l_lin);

        IF l_item_nt IS NULL THEN
          raise no_data_found;

        Else

          for k in 1..l_item_nt.count loop

              case

               when l_item_nt(k) like 'ST*%' then

                       field1:= ltrim(regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3),0);

               when l_item_nt(k) like 'BPR*X*%' then

                       field2 := regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3);

                when l_item_nt(k) like 'TRN*1*%' then

                         field3:= regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3);

                when l_item_nt(k) like 'DTM*007*%' then

                        field4:= regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3);

                when l_item_nt(k) like '%*BE*%' then

                        field5 := regexp_substr(regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3),'[^ ]+', 1, 1);

                        field6 := regexp_substr(regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,3),'[^ ]+', 1, 1);

                         field7  := regexp_substr(parse_spec(l_item_nt(k)),'[^*]+',1,5);

                when l_item_nt(k) like '%*PE*%*ZZ*%' then

                        field8:= regexp_substr(regexp_substr(parse_spec(line),'[^*]+',1,5),'[^ ]+',1,1)

                        field9 := regexp_substr(regexp_substr(parse_spec(line),'[^*]+',1,5),'[^ ]+',1,2);

                 when l_item_nt(k) like 'SE*%' then

                                                     insert into t1(field1,field2,field3,field5,field6,field7,field8,field9)

                            --  values(field1,field2,field3,field5,field6,field7,field8,field9);
                 else
                        dbms_output.put_line ('end of line');

                     end case;

            end loop;

        end if;

end loop;

                     utl_file.fclose(l_out_file);

exception

   when no_data_found then

               dbms_output.put_line('No data found');

   end;

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2014
Added on Dec 9 2013
8 comments
1,751 views