Thanks for the question, M.
Asked: February 24, 2024 - 6:49 am UTC
Last updated: February 26, 2024 - 5:47 am UTC
Version: 19C
Viewed 1000+ times
SQL> Create or replace directory CheckFileExist as 'C:\tmp'; Directory created. SQL> SQL> host ( echo Hello > c:\tmp\TestFile.txt ) SQL> SQL> set serverout on SQL> Declare 2 V_File_Exists Boolean; 3 V_File_Length Number; 4 V_File_Size Number; 5 Directory_Name Nvarchar2(255):='CheckFileExist'; 6 Begin 7 UTL_FILE.FGETATTR (Directory_Name, 'TestFile', V_File_Exists, V_File_Length, V_File_Size); 8 If V_File_Exists 9 Then DBMS_OUTPUT.PUT_LINE('File exists'); 10 Else DBMS_OUTPUT.PUT_LINE('File does not exist'); 11 End if; 12 End; 13 / File does not exist PL/SQL procedure successfully completed. SQL> SQL> set serverout on SQL> Declare 2 V_File_Exists Boolean; 3 V_File_Length Number; 4 V_File_Size Number; 5 Directory_Name Nvarchar2(255):='CheckFileExist'; 6 Begin 7 UTL_FILE.FGETATTR (Directory_Name, 'TestFile.txt', V_File_Exists, V_File_Length, V_File_Size); 8 If V_File_Exists 9 Then DBMS_OUTPUT.PUT_LINE('File exists'); 10 Else DBMS_OUTPUT.PUT_LINE('File does not exist'); 11 End if; 12 End; 13 / File does not exist PL/SQL procedure successfully completed. SQL> SQL> set serverout on SQL> Declare 2 V_File_Exists Boolean; 3 V_File_Length Number; 4 V_File_Size Number; 5 Directory_Name Nvarchar2(255):='CHECKFILEEXIST'; 6 Begin 7 UTL_FILE.FGETATTR (Directory_Name, 'TestFile.txt', V_File_Exists, V_File_Length, V_File_Size); 8 If V_File_Exists 9 Then DBMS_OUTPUT.PUT_LINE('File exists'); 10 Else DBMS_OUTPUT.PUT_LINE('File does not exist'); 11 End if; 12 End; 13 / File exists PL/SQL procedure successfully completed. SQL> SQL>
A reader, February 26, 2024 - 5:47 am UTC
Check out more PL/SQL tutorials on our LiveSQL tool.
PL/SQL reference manual from the Oracle documentation library