In Oracle PL/SQL, om te controleren of BLOB of CLOB leeg is of niet, gebruik de dbms_lob.getlength() functie of dbms_lob.compare() functie. Dit zijn de voorbeelden:
1. Functie dbms_lob.getlength() gebruiken
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. Functie dbms_lob.compare() gebruiken
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;
Evenzo, om te controleren op lege CLOB , verander het type variabele in clob en vervang de empty_blob() functie met empty_clob() functie in de bovenstaande PL/SQL-code.
Verwante tutorials:
- Hoe BLOB opslaan als bestand in PL/SQL?
- Hoe haal ik BLOB uit een bestand in PL/SQL?
- Hoe krijg ik een bestand van BLOB in Oracle?
- Hoe BLOB-gegevens uit Oracle te extraheren met Toad?
- Blob-inhoud (PDF, afbeeldingen) weergeven in een regio op Oracle Apex-pagina
- CLOB-inhoud weergeven in Oracle Apex