Oracle NBLOB data type is used to store binary large objects, such as images, audio, video, etc. The N stands for Network, indicating that NBLOB data can be transmitted and accessed over a network.
(Image Source: Unsplash)1. Define NBLOB field when creating a table
When creating a table, you can define NBLOB field using subtypes of BLOB or CLOB data types.
CREATE TABLE example ( id NUMBER PRIMARY KEY, name VARCHAR2(50), image NBLOB );
2. Insert NBLOB data
When inserting NBLOB data into the table, you can manipulate it using functions from the DBMS_LOB package.
DECLARE l_bfile BFILE := BFILENAME('DIRECTORY', 'image.jpg'); l_blob CLOB; BEGIN DBMS_LOB.OPEN(l_bfile, DBMS_LOB.lob_readonly); DBMS_LOB.loadfromfile(l_blob, l_bfile, DBMS_LOB.getlength(l_bfile)); INSERT INTO example (id, name, image) VALUES (1, 'John Doe', EMPTY_BLOB() || l_blob); DBMS_LOB.CLOSE(l_bfile); END;
3. Query NBLOB data
When querying NBLOB data, you can manipulate it using functions from the DBMS_LOB package.
SELECT id, name, DBMS_LOB.SUBSTR(image, 32767, 1) AS image_part FROM example;
1. Retrieve NBLOB data
You can use functions from the DBMS_LOB package to retrieve data from the NBLOB field.
SELECT id, name, DBMS_LOB.SUBSTR(image, 32767, 1) AS image_part FROM example;
2. Update NBLOB data
When updating NBLOB data, you can first delete the value of the NBLOB field, and then insert new NBLOB data.
UPDATE example SET image = EMPTY_BLOB() WHERE id = 1; -- Delete the existing NBLOB data and insert new NBLOB data as shown in the previous insert example.
3. Delete NBLOB data
When deleting NBLOB data, you can simply set the value of the NBLOB field to empty.
UPDATE example SET image = EMPTY_BLOB() WHERE id = 1; -- Delete the existing NBLOB data.
Thank you for reading. Feel free to leave a comment, follow us for more updates, give us a thumbs up, and thank you for watching!