Dans Oracle PL/SQL, pour vérifier si BLOB ou CLOB est vide ou non, utilisez le dbms_lob.getlength() fonction ou dbms_lob.compare() une fonction. Voici les exemples :
1. Utilisation de la fonction 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. Utilisation de la fonction 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;
De même, pour vérifier les CLOB vides , changez le type de variable en clob et remplacez le empty_blob() fonction avec empty_clob() fonction dans le code PL/SQL ci-dessus.
Tutoriels associés :
- Comment enregistrer un BLOB en tant que fichier en PL/SQL ?
- Comment obtenir un BLOB à partir d'un fichier en PL/SQL ?
- Comment obtenir un fichier à partir d'un BLOB dans Oracle ?
- Comment extraire des données BLOB d'Oracle à l'aide de Toad ?
- Afficher le contenu BLOB (PDF, images) dans une région d'Oracle Apex Page
- Affichage du contenu CLOB dans Oracle Apex