CREATE OR REPLACE DIRECTORY image_dir AS '/home/zabbix/zabbix/create/output_png'
/

CREATE OR REPLACE PROCEDURE LOAD_IMAGE (IMG_ID IN NUMBER, IMG_TYPE IN NUMBER, IMG_NAME IN VARCHAR2, FILE_NAME IN VARCHAR2)
IS
	TEMP_BLOB BLOB := EMPTY_BLOB();
	BFILE_LOC BFILE;
BEGIN
	DBMS_LOB.CREATETEMPORARY(TEMP_BLOB,TRUE,DBMS_LOB.SESSION);
	BFILE_LOC := BFILENAME('IMAGE_DIR', FILE_NAME);
	DBMS_LOB.FILEOPEN(BFILE_LOC);
	DBMS_LOB.LOADFROMFILE(TEMP_BLOB, BFILE_LOC, DBMS_LOB.GETLENGTH(BFILE_LOC));
	DBMS_LOB.FILECLOSE(BFILE_LOC);
	INSERT INTO IMAGES VALUES (IMG_ID, IMG_TYPE, IMG_NAME, TEMP_BLOB);
	COMMIT;
END LOAD_IMAGE;
/

BEGIN
