I have the following script that does what it does: it takes out the contents of a word, and puts it in a blob. But when I run it, I get these errors.
-ORA22275 - > LOB locator not valid -ORA06512 - > Line 29 (DBMS_LOB.fileopen (l_bfile, Dbms_Lob.File_Readonly);)
DIRECTORY PLANTILLAS AS 'D:/Plantillas'
DECLARE
l_bfile BFILE;
l_blob BLOB;
v_blob BLOB;
existe integer;
BEGIN
v_blob := EMPTY_BLOB();
SELECT MAX(id) INTO existe FROM plantillas WHERE NOMBRE = 'plantilla';
IF(existe is null) THEN
INSERT INTO plantillas_ex
(ID, NBYTES, BLOQUE, MIMETYPE)
VALUES
(existe,135680,v_blob,'application/msword')
RETURN BLOQUE INTO l_blob;
END IF;
l_bfile := BFILENAME('PLANTILLAS', 'plantilla1');
DBMS_LOB.fileopen(l_bfile, Dbms_Lob.File_Readonly);
DBMS_LOB.loadfromfile(l_blob,l_bfile,DBMS_LOB.getlength(l_bfile));
DBMS_LOB.fileclose(l_bfile);
COMMIT;
EXCEPTION WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
If someone could or could orient me in this, I would appreciate it. Greetings
----------------------------------------------- -----// SOLUTION \----------------------------------------- ------------------
CREATE OR REPLACE DIRECTORY PLANTILLAS AS 'D:/Plantillas';
DECLARE
l_bfile BFILE;
l_blob BLOB;
v_blob BLOB;
l_length integer;
existe integer;
existe_blp integer;
BEGIN
v_blob := EMPTY_BLOB();
SELECT MAX(id) INTO existe FROM SPAC_P_PLANTDOC WHERE NOMBRE = 'plantilla';
SELECT ID INTO existe_blp FROM SPAC_P_BLP WHERE ID = existe;
IF(existe is not null AND existe_blp <> existe) THEN
INSERT INTO SPAC_P_BLP
(ID, NBYTES, BLOQUE, MIMETYPE)
VALUES
(existe,0,v_blob,'application/msword')
RETURN BLOQUE INTO l_blob;
l_bfile := BFILENAME('PLANTILLAS', 'plantilla1.doc');
DBMS_LOB.fileopen(l_bfile, Dbms_Lob.File_Readonly);
l_length := Dbms_Lob.getlength(l_bfile);
DBMS_LOB.loadfromfile(l_blob,l_bfile,DBMS_LOB.getlength(l_bfile));
DBMS_LOB.fileclose(l_bfile);
update SPAC_P_BLP set nbytes = l_length where id = existe;
END IF;
EXCEPTION WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;