{"id":40194,"date":"2025-10-15T05:00:47","date_gmt":"2025-10-15T05:00:47","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=40194"},"modified":"2025-10-15T05:04:48","modified_gmt":"2025-10-15T05:04:48","slug":"oracle-insert-blob","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/blob\/oracle-insert-blob.html","title":{"rendered":"Oracle Insert BLOB"},"content":{"rendered":"<p>Inserting BLOB data into an Oracle database can be achieved through several methods.<\/p>\n<p>1. Inserting Directly from a Buffer\/Variable:<\/p>\n<pre>  DECLARE\r\n      v_blob_data BLOB;\r\n  BEGIN\r\n      -- Populate v_blob_data with your binary data\r\n      -- For example, from a RAW variable or a file read into memory\r\n      v_blob_data := UTL_RAW.CAST_TO_RAW('Your binary data here'); \r\n\r\n      INSERT INTO your_table (id, blob_column) VALUES (2, v_blob_data);\r\n      COMMIT;\r\n  END;\r\n  \/\r\n<\/pre>\n<p>2. Inserting from another LOB Column:<\/p>\n<pre>INSERT INTO target_table (id, blob_column)\r\nSELECT id, blob_column FROM source_table WHERE id = 123;\r\nCOMMIT;\r\n<\/pre>\n<p>3. Inserting from a File using BFILE and DBMS_LOB:<\/p>\n<pre>  CREATE DIRECTORY images_dir AS 'D:\\Images'; -- Or '\/home\/bob\/images' for Unix\/Linux\r\n  GRANT READ, WRITE ON DIRECTORY images_dir TO your_user;\r\n<\/pre>\n<pre>  DECLARE\r\n      f_lob BFILE;\r\n      b_lob BLOB;\r\n  BEGIN\r\n      INSERT INTO your_table (id, blob_column) VALUES (1, EMPTY_BLOB())\r\n      RETURN blob_column INTO b_lob;\r\n\r\n      f_lob := BFILENAME('IMAGES_DIR', 'your_file.bin');\r\n      DBMS_LOB.FILEOPEN(f_lob, DBMS_LOB.FILE_READONLY);\r\n      DBMS_LOB.LOADFROMFILE(b_lob, f_lob, DBMS_LOB.GETLENGTH(f_lob));\r\n      DBMS_LOB.FILECLOSE(f_lob);\r\n\r\n      COMMIT;\r\n  END;\r\n  \/\r\n<\/pre>\n<p>And you can use <a href=\"https:\/\/www.withdata.com\/dbblobeditor\/\">DBBlobEditor <\/a>to <a href=\"https:\/\/www.withdata.com\/blog\/oralobeditor\/how-to-batch-insert-oracle-blob-data-from-files.html\">Batch insert Oracle table BLOB data from files<\/a>.<\/p>\n<p>See also: <a href=\"https:\/\/www.withdata.com\/blog\/blob\/oracle-blob.html\">Oracle BLOB<\/a>, <a href=\"https:\/\/www.withdata.com\/blog\/oralobeditor\/edit-oracle-blob-data.html\">View and edit BLOB data stored in Oracle<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inserting BLOB data into an Oracle database can be achieved through several methods. 1. Inserting Directly from a Buffer\/Variable: DECLARE v_blob_data BLOB; BEGIN &#8212; Populate v_blob_data with your binary data &#8212; For example, from a RAW variable or a file read into memory v_blob_data := UTL_RAW.CAST_TO_RAW(&#8216;Your binary data here&#8217;); INSERT INTO your_table (id, blob_column) VALUES [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4524],"tags":[97,1325],"class_list":["post-40194","post","type-post","status-publish","format-standard","hentry","category-blob","tag-blob","tag-oracle"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/40194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=40194"}],"version-history":[{"count":3,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/40194\/revisions"}],"predecessor-version":[{"id":40199,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/40194\/revisions\/40199"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=40194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=40194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=40194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}