Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Location
    US
    Posts
    4

    Unanswered: Replacing string in a file in PL/SQL

    Hi,

    I need to replace a string (maxextent 10K) with string (maxextent unlimited) using a PL/SQL program. I have to do it in multiple files and I am using a UTL_FILE package to open and write to the file. How can I search the string in a file and replace it.

    Please give some ideas.

    Thanks,
    Arun

  2. #2
    Join Date
    Dec 2003
    Location
    Oklahoma, USA
    Posts
    354

    Lightbulb

    I would do it like this (code not tested, just my "process"):

    Code:
    huge_string_var varchar2(32000);
    
    begin
       fhandle := fopen( my_file );
    
       while not feof loop
            temp_var := fread( fhandle);
            huge_string_var := huge_string_var || temp_var;
    
            pos_v := instr( huge_string_var, 'search_string' );
            if pos_v > 0 then
                -- I found the string, so do something
                -- next line is to continue the search for more matches, but if not necessary just exit
                huge_string_var := substr( huge_string_v, pos_v + length( 'search_string' );
             end if;
        end loop;
    end;
    Reason for doing it this way, is because you never know where the input string will be broken up on the FREAD. Happy to explain further if you need.

    JoeB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •