Categorias
iiiiii
oracle apex
Descripcion
Exportar un blob a una carpeta en el servidor
html
/*Primero que todo:
1. crear un directorio en el servidor con los permisos de leer y escribir
2. crear una instancia de directorio en oracle..
3. se debe dar permisos al usuario de la base de datos a la nueva instancia de directorio de leer y escribir en esa instancia
nota:
1.la instancia de directorio es -> DIR_REMUNER_IMG . esto apunta a una ruta real del servidor.
2. la tabla donde se guarda las imagenes temporalmente es wwv_flow_file_objects$
*/
DECLARE
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
-- Get LOB locator
SELECT BLOB_CONTENT
INTO l_blob
FROM wwv_flow_file_objects$
WHERE substr(name,1,instr(name,'/')-1) = 'F870364666'; --'2,15263417223153E16'; --:P128_ID_GENERATED;
l_blob_len := DBMS_LOB.getlength(l_blob);
-- Open the destination file.
--l_file := UTL_FILE.fopen('BLOBS','MyImage.gif','w', 32767);
l_file := UTL_FILE.fopen('DIR_REMUNER_IMG','MyImage.jpg','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);
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;
RAISE;
END;