在sqlplus中操作blob和clob
生活随笔
收集整理的這篇文章主要介紹了
在sqlplus中操作blob和clob
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Tom在他的《Expert one on one oracle》給出了sqlplus中將文件load進BLOB或者CLOB字段的例子。這里保存一份以備急用。
create directory utllobdir as 'd:' create table blobtest(col1 BLOB); create table clobtest(col1 cLOB); --insert BLOB declare a_blob BLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','teslob.doc'); begin insert into blobtest values (empty_blob()) returning col1 into a_blob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_blob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end; --update BLOB declare a_blob BLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','log.txt'); begin update blobtest set col1=empty_blob() where rownum=1 returning col1 into a_blob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_blob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end; --insert CLOB create table clobtest(col1 CLOB); declare a_clob CLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','teslob.doc'); begin insert into clobtest values (empty_clob()) returning col1 into a_clob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_clob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end; --update CLOB declare a_clob CLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','log.txt'); begin update clobtest set col1=empty_clob() where rownum=1 returning col1 into a_clob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_clob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end;
create directory utllobdir as 'd:' create table blobtest(col1 BLOB); create table clobtest(col1 cLOB); --insert BLOB declare a_blob BLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','teslob.doc'); begin insert into blobtest values (empty_blob()) returning col1 into a_blob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_blob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end; --update BLOB declare a_blob BLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','log.txt'); begin update blobtest set col1=empty_blob() where rownum=1 returning col1 into a_blob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_blob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end; --insert CLOB create table clobtest(col1 CLOB); declare a_clob CLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','teslob.doc'); begin insert into clobtest values (empty_clob()) returning col1 into a_clob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_clob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end; --update CLOB declare a_clob CLOB; bfile_name BFILE := BFILENAME('ULTLOBDIR','log.txt'); begin update clobtest set col1=empty_clob() where rownum=1 returning col1 into a_clob; dbms_lob.fileopen(bfile_name); dbms_lob.loadfromfile(a_clob, bfile_name, dbms_lob.getlength(bfile_name)); dbms_lob.fileclose(bfile_name); commit; end;
通過查看lob字段的長度判斷是否插入成功
select dbms_lob.getlength(col1) from blobtest; select dbms_lob.getlength(col1) from clobtest;總結
以上是生活随笔為你收集整理的在sqlplus中操作blob和clob的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ORA-600[4194]/[4193]
- 下一篇: ORACLE:RETURNING 子句