I am using the below code to create a ORDS service which will upload a file to a DBA directory.
Could anyone assist me to make the following work. I am getting an error trying to compile this.
DECLARE
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB := :body;
-- l_file_name VARCHAR2 (100) := :fileName;
l_blob_len INTEGER;
l_reqid NUMBER;
BEGIN
l_blob_len := DBMS_LOB.getlength(l_blob);
-- Open the destination file.
l_file := UTL_FILE.fopen('XX_FILE','XX_FILE_NAME.csv','wb', 32767);
-- Read chunks of the BLOB and write them to the file
-- until complete.
WHILE l_pos <= l_blob_len LOOP
DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
-- Close the file.
UTL_FILE.fclose(l_file);
HTP.P('File Upload Success');
EXCEPTION
WHEN OTHERS THEN
-- Close the file if something goes wrong.
IF UTL_FILE.is_open(l_file) THEN
UTL_FILE.fclose(l_file);
END IF;
HTP.P('Error: ' || SQLERRM);
END;
Error report –
ORA-06550: line 6, column 24:
PLS-00382: expression is of wrong type
ORA-06550: line 0, column 1:
PL/SQL: Compilation unit analysis terminated
06550. 00000 – “line %s, column %s:n%s”
*Cause: Usually a PL/SQL compilation error.
*Action: