
然后插入的时候,取它的绝对路径
insert into 表名 values(@"C:/123.JPG")
可以用BLOB(string)函数将字符串转化为blob再插入,如下:
create table test(c1 blob(200))insert into test values(blob('Hello, world'))
其他的方法可能需要用别的语言来写了,这种是在数据库下 *** 作
在internal这个用户下给scott用户授权如下:SQL>grant create any directory to scott
SQL>grant create any library to scott
在scott这个用户下执行下述语句:
SQL>create table bfile_tab (bfile_column BFILE)
SQL>create table utl_lob_test (blob_column BLOB)
SQL>create or replace directory utllobdir as 'C:\DDS\EXTPROC'
SQL>set serveroutput on
然后执行下面语句就将C:\DDS\EXTPROC目录下的word文件COM.doc存入到utl_lob_test
表中的blob_column字段中了。
declare
a_blob BLOB
a_bfile BFILE := BFILENAME('UTLLOBDIR','COM.doc')--用来指向外部 *** 作系统
文件
begin
insert into bfile_tab values (a_bfile)
returning bfile_column into a_bfile
insert into utl_lob_test values (empty_blob())
returning blob_column into a_blob
dbms_lob.fileopen(a_bfile)
dbms_lob.loadfromfile(a_blob, a_bfile, dbms_lob.getlength(a_bfile))
dbms_lob.fileclose(a_bfile)
commit
end
/
SQL>show errors
此时可以使用DBMS_LOB包的getlength这个procedure来检测是否已经将该word文件存入
到blob字段中了。如:
SQL>select dbms_lob.getlength(blob_column) from UTL_LOB_TEST
结果如下:
DBMS_LOB.GETLENGTH(BLOB_COLUMN)
-------------------------------
例如 Table1中有两个字段,一个是ID(int类型),一个是content(text类型)。则在Query Analyzer中执行SQL语句:insert into Table1 values(1,'a test content')就可以了啊。要显示的话,要双击一下。欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)