2 Replies Latest reply: Mar 8, 2013 3:30 PM by salute-Salem RSS

    text_io package

    salute-Salem
      db and dev 10g rel2 ,
      hi all ,
      i am trying to get data from a .csv file into a forms builder block with using this code :
      declare 
           x text_io.file_type ;
           a number ; 
           b number ; 
           c number ; 
           d number ; 
      begin 
           x := text_io.fopen('D:\Original\pinginfoview\test.csv','r') ; 
           loop
           text_io.get_line(x,:t0) ;
           a := instr(:t0,',') ;
           :t1 := substr(:t0,1,a-1) ;
           
           
           b := instr(:t0,',',1,2) ; 
           :t2 := substr(:t0,a+1,13) ;
           
           c := instr(:t0,',',1,3) ; 
           :t3 := substr(:t0,b+1,13) ; 
           
           d := instr(:t0,',',1,4) ;      
           :t4 := substr(:t0,c+1,1) ; 
           down ;
           end loop ; 
           exception 
                when no_data_found 
                then 
                message('you reached the end of the file') ; 
                message('you reached the end of the file') ;   
           text_io.fclose(x);
           end ; 
            
      the problem is it reads only the last line ,
      by the way , i am using a tabular block .

      thanks in advance
        • 1. Re: text_io package
          HamidHelal
          semsem wrote:
          db and dev 10g rel2 ,
          hi all ,
          i am trying to get data from a .csv file into a forms builder block with using this code :

          declare
               x text_io.file_type ;
               a number ;
               b number ;
               c number ;
               d number ;
          begin
               x := text_io.fopen('D:\Original\pinginfoview\test.csv','r') ;
          add here
          go_block('block_name');
          first_reocrd;
          >     loop
               text_io.get_line(x,:t0) ;
               a := instr(:t0,',') ;
               :t1 := substr(:t0,1,a-1) ;
               
               
               b := instr(:t0,',',1,2) ;
               :t2 := substr(:t0,a+1,13) ;
               
               c := instr(:t0,',',1,3) ;
               :t3 := substr(:t0,b+1,13) ;
               
               d := instr(:t0,',',1,4) ;      
               :t4 := substr(:t0,c+1,1) ;
               down ;
          remove the down;
          and add
          NEXT_RECORD;
               end loop ;
               exception
                    when no_data_found
                    then
                    message('you reached the end of the file') ;
                    message('you reached the end of the file') ;
               text_io.fclose(x);
               end ;
               
          the problem is it reads only the last line ,
          by the way , i am using a tabular block .
          Hope it works..
          • 2. Re: text_io package
            salute-Salem
            i do not know what happened , but
            i had another text item :t0 in another control block which has the whole line of the file , and when i wrote down in the code , i figured out that it goes down the :t0 , not the block i want .

            so , i used go_block , last record built-ins , and dealt with the issue , and it solved now , thanks a lot man