'UNIQUE NAMES IN ORACLE PL/SQL

I have a procedure that converts the result of a specific query in a CSV File which is saved in a directory in the server. My question is that is there any way that i can generate unique names for the file every time i save it?



Solution 1:[1]

try this

-- not tested

select to_char( sysdate,'yyyymmddhh24miss' ) || '.txt' File_nm from dual;
spool &File_nm ;
-- run query
spool off;

Solution 2:[2]

If you create a SEQUENCE, you can increment the sequence each time you go to write your file.

DECLARE
    l_filename   VARCHAR2 (200);
BEGIN
    SELECT 'somename_' || seq_name.NEXTVAL INTO l_filename FROM DUAL;
END;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Himanshu Kandpal
Solution 2 EJ Egyed