In Oracle PL/SQL, per verificare se BLOB o CLOB è vuoto o meno, usa dbms_lob.getlength() funzione o dbms_lob.compare() funzione. Ecco gli esempi:
1. Utilizzo della funzione dbms_lob.getlength()
declare
vblob blob;
Cursor c_blob
is
select content into vblob
from employee_docs
where employee_id = 101;
begin
open c_blob;
fetch c_blob into vblob;
close c_blob;
/* if the vblob is empty then the length would be 0 */
if dbms_lob.getlength(vblob) = 0 then
raise_application_error(-20001, 'Blob is empty.');
end if;
-- do anything with vblob
end; 2. Utilizzo della funzione dbms_lob.compare()
declare
vblob blob;
Cursor c_blob
is
select content into vblob
from employee_docs
where employee_id = 101;
begin
open c_blob;
fetch c_blob into vblob;
close c_blob;
/* if vblob is equal to an empty_blob, means it is empty */
if dbms_lob.compare(vblob, empty_blob()) = 0 then
raise_application_error(-20001, 'Blob is empty.');
end if;
-- do anything with vblob
end;
Allo stesso modo, per verificare la presenza di CLOB vuoto , cambia il tipo di variabile in clob e sostituisci empty_blob() funzione con empty_clob() funzione nel codice PL/SQL sopra.
Esercitazioni correlate:
- Come salvare BLOB come file in PL/SQL?
- Come ottenere BLOB da file in PL/SQL?
- Come ottenere file da BLOB in Oracle?
- Come estrarre i dati BLOB da Oracle utilizzando Toad?
- Visualizza i contenuti BLOB (PDF, immagini) in un'area nella pagina Oracle Apex
- Visualizzazione dei contenuti CLOB in Oracle Apex