y2j
y2j

Reputation: 207

Copying files from one directory to other in plsql

I want to copy files from one directory to other using "UTL" function.

source directory = EXPORT_PPM_TEMP
target directory = EXPORT_PPM

I am saving all files names in a collections and looping through the collections and copying to target directory.

name of collection = vc_file_name.

I am using below code to copy. It is copying all files but some files are copying as empty files

FOR i IN 1 .. vc_index    
      LOOP  
  vc_lp_file_name := vc_file_name(i);

  Utl_File.Fcopy('EXPORT_PPM_TEMP',vc_lp_file_name,'EXPORT_PPM',vc_lp_file_name);
  Utl_File.Fremove('EXPORT_PPM_TEMP',vc_lp_file_name);

END LOOP;

what is the reason behind coping some files with content and some without contents

Upvotes: 1

Views: 13395

Answers (1)

Shadow
Shadow

Reputation: 13

DECLARE
   in_file  utl_file.file_type;
   s        VARCHAR2(200);
   c        NUMBER := 0;
   out_file utl_file.file_type;
BEGIN
   in_file  := utl_file.fopen('/scratch/fccus/dbDump/BT', 'rocs.001.001.06.xml', 'R');
   out_file := utl_file.fopen('/scratch/fccus/dbDump/BT/success', 'rocs.001.001.06.xml', 'W');
   LOOP
      utl_file.get_line(in_file, s);
      utl_file.put_line(out_file, s);
      --dbms_output.put_line(s);
      c := c + 1;
   END LOOP;
EXCEPTION
   WHEN no_data_found THEN
      utl_file.fclose(in_file);
      utl_file.fclose(out_file);
      dbms_output.put_line('Number of lines: ' || c);
END;

Upvotes: 0

Related Questions