DB2 Version 9.7 for Linux, UNIX, and Windows

FRENAME procedure - Rename a file

The FRENAME procedure renames a specified file. Renaming a file effectively moves a file from one location to another.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-UTL_FILE.FRENAME--(--location--,--filename--,--dest_dir--,--dest_file--+------------+--)-><
                                                                          '-,--replace-'      

Procedure parameters

location
An input argument of type VARCHAR(128) that specifies the alias of the directory that contains the file that you want to rename.
filename
An input argument of type VARCHAR(255) that specifies the name of the file that you want to rename.
dest_dir
An input argument of type VARCHAR(128) that specifies the alias of the destination directory.
dest_file
An input argument of type VARCHAR(255) that specifies the new name of the file.
replace
An optional input argument of type INTEGER that specifies whether to replace the file dest_file in the directory dest_dir if the file already exists:
1
Replaces existing file.
0
Throws an exception if the file already exists. This is the default if no value is specified for replace.

Authorization

EXECUTE privilege on the UTL_FILE module.

Example

Rename a file, empfile.csv, that contains a comma-delimited list of employees from the emp table.

SET SERVEROUTPUT ON@

CREATE PROCEDURE proc1()
BEGIN
  DECLARE    v_dirAlias      VARCHAR(50) DEFAULT 'empdir';
  DECLARE    v_src_file      VARCHAR(20) DEFAULT 'oldemp.csv';
  DECLARE    v_dest_file     VARCHAR(20) DEFAULT 'newemp.csv';
  DECLARE    v_replace       INTEGER DEFAULT 1;
  CALL UTL_FILE.FRENAME(v_dirAlias,v_src_file,v_dirAlias,
        v_dest_file,v_replace);
  CALL DBMS_OUTPUT.PUT_LINE('The file ' || v_src_file || 
    ' has been renamed to ' || v_dest_file);    
END@

CALL proc1@

This example results in the following output:

The file oldemp.csv has been renamed to newemp.csv