{"id":144,"date":"2014-04-09T10:35:32","date_gmt":"2014-04-09T03:35:32","guid":{"rendered":"https:\/\/sanmaharjan.com\/?p=144"},"modified":"2014-04-09T10:35:32","modified_gmt":"2014-04-09T03:35:32","slug":"load-file-into-database-as-blob","status":"publish","type":"post","link":"https:\/\/sanmaharjan.com\/load-file-into-database-as-blob\/","title":{"rendered":"Load File into Database as Blob"},"content":{"rendered":"
You can find lots of procedure or steps to load file from filesystem to database. Usage: You can find lots of procedure or steps to load file from filesystem to database. one of the easy method is to make a function. Sample of function:- CREATE OR REPLACE FUNCTION FN_FILE_BLOB(V_FILENAME VARCHAR2, V_DIRECTORY VARCHAR2) RETURN BLOB IS src_loc BFILE; dest_loc BLOB:=empty_blob(); BEGIN SRC_LOC := BFILENAME(V_DIRECTORY, V_FILENAME); DBMS_LOB.OPEN(src_loc, DBMS_LOB.LOB_READONLY); DBMS_LOB.CREATETEMPORARY(lob_loc => dest_loc, cache => […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[51,63,64,12],"_links":{"self":[{"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/posts\/144"}],"collection":[{"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":1,"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/posts\/144\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanmaharjan.com\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\none of the easy method is to make a function.
\nSample of function:-
\nCREATE OR REPLACE FUNCTION FN_FILE_BLOB(V_FILENAME VARCHAR2, V_DIRECTORY VARCHAR2) RETURN BLOB
\nIS
\nsrc_loc BFILE;
\ndest_loc BLOB:=empty_blob();
\nBEGIN
\nSRC_LOC := BFILENAME(V_DIRECTORY, V_FILENAME);
\nDBMS_LOB.OPEN(src_loc, DBMS_LOB.LOB_READONLY);
\nDBMS_LOB.CREATETEMPORARY(lob_loc => dest_loc, cache => true , dur => dbms_lob.session);
\nDBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);
\nDBMS_LOB.LOADFROMFILE(dest_lob => dest_loc, src_lob => src_loc , amount => DBMS_LOB.getLength(src_loc));
\nDBMS_LOB.CLOSE(src_loc);
\nDBMS_LOB.CLOSE(dest_loc);
\nRETURN dest_loc;
\nEXCEPTION
\nWHEN Others THEN
\nDbms_Output.Put_Line(SQLERRM);
\nRETURN NULL;
\nEND;
\n\/
\n<\/code><\/p>\n SELECT FN_FILE_BLOB('image1.jpg','DUMP_DIR') FROM DUAL;<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"