6 Replies Latest reply: Jan 2, 2013 5:33 PM by Andreas Weiden RSS

    text_io.fopen

    salute-Salem
      db and dev 10grel2
      hi all ,
      i am trying to use text_io.fopen , and i am getting the error "ora-302000" , i've read that this error appears if i am not writing the complete path of the file i want to open , and that did not happen .
      my file name is new and it resides into the f:\ drive , and i am writing this code :

      declare
           
           x Text_IO.File_Type;
           BEGIN
           x := TEXT_IO.FOPEN('f:\new.txt','R');
           end ;

      so why i am facing this error and the file does not open ?

      thanks
        • 1. Re: text_io.fopen
          salute-Salem
          i do not know what happens , i created a new form , then put a button , then i 've written this code in it , and i think it 's the same code , but no action happens , and no errors , nothing happens

          declare
               x Text_IO.File_Type;
          begin
          x := Text_IO.Fopen('f:\new.txt', 'R');
               end ;
          • 2. Re: text_io.fopen
            salute-Salem
            1- i figured out that this "nothing happens" means that the file is opened , but sure i can not see it .
            is this the ordinary thing ?
            2- i am trying to use text_io.get_line , and it can read the first line of the .txt file , but there are two problems here :

            1- i want to read a .xlsx file , and when i try to do so , i get something strange , it is not an error ,
            it is "PK000" ,

            my code is :

            declare
                 x Text_IO.File_Type;
                 linebuf varchar2(90) ;

            begin
            x := Text_IO.Fopen('f:\book1.xlsx ', 'R');
            if form_success
                 then
                 message('succeeded') ;
            end if ;
            Text_IO.Get_Line(x,linebuf);
            message(linebuf) ;
            message(linebuf) ;
            end ;

            i think it reads the line as encrypted or something because my first field in the excel sheet contains "h" charachter , nothing else .


            second problem : i need to read the last record .

            thanks a lot
            • 3. Re: text_io.fopen
              kikolus
              Hi,
              1. ora-302000 usualy means that you have no permison to read the file or file doesn't exists.
              2. xlsx file is a ZIP file in fact, and ZIP file signature starts always with two chars PK (initials of the inventor Phil Katz)
              kikolus

              Edited by: kikolus on 2013-01-02 07:08
              • 4. Re: text_io.fopen
                salute-Salem
                and ZIP file signature starts always with two chars PK
                why it reads the signature , not the file content , especially if the file is already opened ?

                by the way , the situation is changed now . i saved my excel file in .csv format , and the code works fine with it , but
                by big problem is : i need to read the very last record each time i press a button and assign the excel record to a record on my form ??? this is the big problem i am facing , how to read the last record and assign it to my form's record or to my database table , ??? then i can query it from my form .

                can not i do this with "sql loader" ? can i restrict records with "sql loader" to get the latest record entered based on
                sysdate for instance ?
                thanks

                Edited by: semsem on Dec 31, 2012 5:36 AM

                Edited by: semsem on Dec 31, 2012 5:51 AM
                • 5. Re: text_io.fopen
                  kikolus
                  >
                  why it reads the signature , not the file content , especially if the file is already opened ?
                  >
                  Cause file signature is a part of file :) .Try open *.xlsx file in any text editor (e.g. Notepad) then you'll see at first two position letters P and K
                  Regarding last row extraction: there is another your thread when I suggest to create external table from your file - try to use solution I wrote
                  kikolus
                  • 6. Re: text_io.fopen
                    Andreas Weiden
                    Maybe you could provide the data-structure you get from the csv-file?