If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Replacing string in a file in PL/SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-03, 10:29
arun1581 arun1581 is offline
Registered User
 
Join Date: Dec 2003
Location: US
Posts: 4
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
Reply With Quote
  #2 (permalink)  
Old 12-16-03, 11:41
joebednarz joebednarz is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On