UTL_FILE.PUT_LINE_UDF

Definition

This user-defined function (UDF) is used to replicate the functionality of the Oracle UTL_FILE_PUT_LINE procedure.

UTL_FILE.PUT_LINE_UDF(FILE VARCHAR,BUFFER VARCHAR)

Parameters

FILE VARCHAR

The file to open and save the new buffer.

BUFFER VARCHAR

The buffer to be saved on the defined file.

Returns

Returns a varchar with the result.

Usage example

To review the lines in the file, there are two ways: Downloading the file from the Snowflake CLI or briefly review the information with SELECT * FROM UTL_FILE.FOPEN_TABLES_LINES; but only if the file has not been closed.

Input:

CREATE OR REPLACE PROCEDURE PROC()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS CALLER
AS
$$
   DECLARE
    file_data  VARIANT;
   BEGIN
   
    CALL UTL_FILE.FOPEN_UDF('test2.csv','a');
    
    SELECT
      *
    INTO
      file_data
    FROM
      TABLE(RESULT_SCAN(LAST_QUERY_ID()));

    CALL UTL_FILE.PUT_LINE_UDF(:file_data,'New line');


    CALL UTL_FILE.FCLOSE_UDF(:file_data);
 
      
   END
$$;

CALL PROC();

Output:

null

Last updated