DB2 Version 9.7 for Linux, UNIX, and Windows

IS_OPEN function - Determine whether a specified file is open

The IS_OPEN function determines whether a specified file is open.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-UTL_FILE.IS_OPEN--(--file--)--------------------------------><

Return value

This function returns a value of type BOOLEAN that indicates if the specified file is open (TRUE) or closed (FALSE).

Function parameters

file
An input argument of type UTL_FILE.FILE_TYPE that contains the file handle.

Authorization

EXECUTE privilege on the UTL_FILE module.

Example

The following example demonstrates that before writing text to a file, you can call the IS_OPEN function to check if the file is open.

SET SERVEROUTPUT ON@

CREATE OR REPLACE PROCEDURE proc1()
BEGIN
  DECLARE  v_filehandle    UTL_FILE.FILE_TYPE;
  DECLARE  isOpen          BOOLEAN;
  DECLARE  v_dirAlias      VARCHAR(50) DEFAULT 'mydir';
  DECLARE  v_filename      VARCHAR(20) DEFAULT 'myfile.csv';  
  CALL UTL_DIR.CREATE_OR_REPLACE_DIRECTORY('mydir', '/tmp');
  SET v_filehandle = UTL_FILE.FOPEN(v_dirAlias,v_filename,'w');
  SET isOpen = UTL_FILE.IS_OPEN( v_filehandle );
    IF isOpen != TRUE THEN
      RETURN -1;
    END IF;
  CALL UTL_FILE.PUT_LINE(v_filehandle,'Some text to write to the file.');
  CALL DBMS_OUTPUT.PUT_LINE('Updated file: ' || v_filename);
  CALL UTL_FILE.FCLOSE(v_filehandle);
END@

CALL proc1@

This example results in the following output.

Updated file: myfile.csv