版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1Copyright Oracle Corporation, 2001. All rights reserved.LOBLOB数据和数据和OSOS文件文件1-2Copyright Oracle Corporation, 2001. All rights reserved.三种三种LOBLOB类型类型BLOB:大二进制数据,例如图像,声音,视频CLOB:大字符串BFILE:仅存放操作系统文件的指针1-3Copyright Oracle Corporation, 2001. All rights reserved.LOB存储存储当访问数据库当访问数据库LOB数据时,需要使用数据时,需要使用LOB定
2、位符,定位符,LOB定位符是指向定位符是指向LOB数据的指针,当数据的指针,当LOB列插入数列插入数据时,据时,ORACLE会将会将LOB定位符存放在数据库表,而定位符存放在数据库表,而LOB数据则存放在数据则存放在LOB段或者表段中段或者表段中1-4Copyright Oracle Corporation, 2001. All rights reserved.LOB列状态列状态 当访问当访问LOB列时,需要确定列时,需要确定LOB列状态,有三种状态:列状态,有三种状态:NULL:列中不存在:列中不存在LOB定位符,并且不包含数据定位符,并且不包含数据EMPTY:列中存在:列中存在LOB定位符
3、,但不包含数据定位符,但不包含数据POPULATED:列中即包含:列中即包含LOB定位符,也包含数据定位符,也包含数据 1-5Copyright Oracle Corporation, 2001. All rights reserved.测试测试clob数据表数据表 create table clob_test( id number(6) primary key, name varchar2(50), txt clob);1-6Copyright Oracle Corporation, 2001. All rights reserved.初始化数据初始化数据-chr(10)为换行符insert
4、 into clob_test values (1,张三,基本信息|chr(10)|出生于北京市);-用内置函数插入一个空LOB定位符insert into clob_test values (2,李四,empty_clob();commit;1-7Copyright Oracle Corporation, 2001. All rights reserved.查询数据查询数据 /*查询数据,其实赋给v_txt的是lob定位符指针*/declare v_txt clob; begin select txt into v_txt from clob_test where id=1; dbms_ou
5、tput.put_line(v_txt); dbms_output.put_line(length(v_txt); -适合大数据 dbms_output.put_line(dbms_lob.getlength(v_txt);end;1-8Copyright Oracle Corporation, 2001. All rights reserved.DBMS_LOB包的包的write过程写入数据过程写入数据 /*用DBMS_LOB包的write过程写入数据必须要用FOR UPDATE 锁定编辑的行*/declare v_txt clob; begin select txt into v_txt
6、from clob_test where id=1 for update; -参数分别是lob定位符,写入的字符数,写入起始位置,写入的数据 dbms_lob.write(v_txt,5,1,hello,world); commit;end;1-9Copyright Oracle Corporation, 2001. All rights reserved.DBMS_LOB包的包的writeappend过程追加数据过程追加数据/*由于clob列数据很庞大,不可能一次性写入所以需要用DBMS_LOB包的writeappend过程追加数据*/declare v_txt clob; v_temp v
7、archar2(100); begin select txt into v_txt from clob_test where id=1 for update; -参数分别是lob定位符,写入的字符数,写入起始位置,写入的数据 v_temp := ,是少先队员; dbms_lob.writeappend(v_txt,length(v_temp),v_temp); v_temp := ,是三好学生; dbms_lob.writeappend(v_txt,length(v_temp),v_temp); commit;end;1-10Copyright Oracle Corporation, 2001
8、. All rights reserved.读取读取CLOB数据数据 declare v_txt clob; v_temp varchar2(100); v_offset integer; v_amount integer := 40;begin select txt into v_txt from clob_test where id=1 for update; -参数:in 指针,in out实际读取字符数,in 偏移量,out 返回字符串 dbms_lob.read(v_txt,v_amount,10,v_temp); dbms_output.put_line(v_amount); db
9、ms_output.put_line(v_temp); commit;end;1-11Copyright Oracle Corporation, 2001. All rights reserved.测试测试bfile数据表数据表create table bfile_test( id number(6) primary key, name varchar2(50), doc bfile);1-12Copyright Oracle Corporation, 2001. All rights reserved.目录对象目录对象 /*管理员登陆创建一个目录对象,并且将这个目录的读写权限授予SCOTT用
10、户*/create directory user_dir as F:my_oracle_dir;grant read,write on directory USER_DIR to scott;1-13Copyright Oracle Corporation, 2001. All rights reserved.插入一个外部文件插入一个外部文件 insert into bfile_test values (1,张三,bfilename(USER_DIR,test.txt);insert into bfile_test values (2,张三,bfilename(USER_DIR,abc/tes
11、t.txt);insert into bfile_test values (3,张三,bfilename(USER_DIR,weather3.png);commit;1-14Copyright Oracle Corporation, 2001. All rights reserved.测试测试blob数据表数据表 create table blob_test( id number(6) primary key, name varchar2(50), doc blob);1-15Copyright Oracle Corporation, 2001. All rights reserved.插入二
12、进制数据插入二进制数据 /*实际上是把目录中的二进制文件bfile数据插入*/declare blob_loc blob; bfile_loc bfile; src_offset integer := 1; dest_offset integer := 1; begin -初始化blob列值 insert into blob_test values (1,张三,empty_blob(); select doc into blob_loc from blob_test where id=1 for update;1-16Copyright Oracle Corporation, 2001. Al
13、l rights reserved.插入二进制数据(续)插入二进制数据(续) bfile_loc := bfilename(USER_DIR,Weather3.png); -只读方式打开文件,只能写0 dbms_lob.fileopen(bfile_loc,0); -复制数据,参数:in目标数据,in源数据,in复制长度,in out目标起始位置,in out源起始位置 dbms_lob.loadblobfromfile(blob_loc,bfile_loc,dbms_lob.getlength(bfile_loc),dest_offset,src_offset); -关闭bfile文件 db
14、ms_lob.fileclose(bfile_loc); commit;end;1-17Copyright Oracle Corporation, 2001. All rights reserved.读写读写OS文件文件读写读写OS文件也必须建立目录对象文件也必须建立目录对象并授予用户目录访问权限并授予用户目录访问权限 读写文件的模式:读写文件的模式:r只读只读 w写入写入 a追加写入追加写入 1-18Copyright Oracle Corporation, 2001. All rights reserved.写入文本文件写入文本文件 declare fileId utl_file.file
15、_type;-文件标识begin -追加写入方式打开文件,文件不存在会自动创建 fileId := utl_file.fopen(USER_DIR,1.txt,a); -写入数据 utl_file.put_line(fileId,中国人民解放军); utl_file.put_line(fileId,hello,world); utl_file.put_line(fileId,1234567); -关闭文件 utl_file.fclose(fileId);end;1-19Copyright Oracle Corporation, 2001. All rights reserved.读取文本文件数据读取文本文件数据declare fileId utl_file.file_type;-文件标识 v_temp varchar2(1000); f_exists boolean;-文件是否存在 f_len integer;-文件大小 block_size integer;-块大小 begin -获得文件信息 utl_file.fgetattr(USER_DIR,1.tx
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年学生逆向思维的培养研究
- 室外道路及管网工程施工设计方案
- 物流中心管理系统仓储物流解决方案
- 实验动物质量检测协议书
- 网约车的电子协议书
- 饮品点位服务协议书模板
- 施工方案编制难点(3篇)
- 钢架柜子施工方案(3篇)
- 春节服装活动策划方案(3篇)
- 电器自控施工方案(3篇)
- 龙盘工程简介
- 高炉基本操作制度
- 安徽中元化工集团有限公司2万吨每年二氯异氰尿酸钠资源综合利用联产2万吨每年三氯异氰尿酸项目环境影响报告书
- 四年级上册数学人教版课件第3课时 一格代表多个单位的条形统计图
- 《国际共产主义运动史》课程教学大纲
- YY/T 1836-2021呼吸道病毒多重核酸检测试剂盒
- 安全经验分享-办公室职业病
- GB/T 32291-2015高压超高压安全阀离线校验与评定
- 外科学课件:第七章-重症监测治疗与复苏
- 团队与团队凝聚力打造课件
- 古代汉语诗律的知识
评论
0/150
提交评论