Reputation: 1
I built form that upload files in oracle apex as blob. When I submit file I want to change file name by using any of plsql or JavaScript.
All files name are in table.
So I want to get the name from table and change uploading file.
Can you help me please?
Upvotes: 0
Views: 268
Reputation: 849
Use the utl_file.frename procedure. This procedure renames an existing file to a new name. The documentation doesn't help much, but it might be worth checking it out: https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/UTL_FILE.html#GUID-AE2D7739-9CD3-42EE-A3A5-29A7CAA70125
Here is an example:
DECLARE
v_old_location VARCHAR2(100) := 'MY_DIR'; -- Directory where the file currently exists
v_new_location VARCHAR2(100) := 'MY_NEW_DIR'; -- Directory where you want to move the file
v_old_file_name VARCHAR2(100) := 'old_file.txt'; -- Name of the file you want to rename
v_new_file_name VARCHAR2(100) := 'new_file.txt'; -- New name for the file
v_file_exists BOOLEAN;
BEGIN
-- Check if the old file exists
v_file_exists := UTL_FILE.FGETATTR(location => v_old_location, filename => v_old_file_name) IS NOT NULL;
IF v_file_exists THEN
-- If the file exists, rename it
UTL_FILE.FRENAME(
src_location => v_old_location,
src_filename => v_old_file_name,
dest_location => v_new_location,
dest_filename => v_new_file_name
);
DBMS_OUTPUT.PUT_LINE('File renamed successfully.');
ELSE
DBMS_OUTPUT.PUT_LINE('File does not exist in the specified location.');
END IF;
END;
/
Upvotes: 1