ORACLE大对象存储
--创建有大对象字段的一张表
create table test001
(
fname varchar2(50),
content blob
)
select * from dba_users;
select * from test001
--(一)..准备插入大对象
--1. 创建文件存放目录(让Oracle管理,该目录)
create or replace directory test_dir
as
'e:\Pictures';
--2.可以将该目录授权给其他用户访问
grant read,write on directory test_dir to scott;
--(二).准备将大对象,存放在test001表中
declare
tempimg blob;--定义临时变量存放数据
tempdir bfile := bfilename('TEST_DIR','Azul.jpg');--非常重要:所有数据都是大写存放的
begin
insert into test001 values ('first.jpg',empty_blob()) returning content into tempimg;
--使用内置的包,给tempimg写入数据
dbms_lob.fileopen(tempdir);--打开指定文件
dbms_lob.loadfromfile(tempimg,tempdir,dbms_lob.getlength(tempdir));
dbms_lob.fileclose(tempdir);--关闭文件
dbms_output.put_line('恭喜你,终于成功了!!!');
commit;
end ;
select * from test001
select * from dba_directories
--将Blob对象,写成磁盘文件
declare
l_file utl_file.file_type;--定义写入磁盘文件的类型和格式
l_buffer raw(32767);--定义缓冲区大小
l_amount binary_integer := 3276; --每次位移个数
l_pos int :=1;--开始位置
l_blob blob;--临时数据存放
l_blob_len int;--总长度
begin
select content into l_blob from test001; --将数据库中的数据,存放在blob变量中
--获取blob文件的长度
l_blob_len := dbms_lob.getlength(l_blob);
--准备写入磁盘文件
l_file := utl_file.fopen('TEST_DIR','HHAHAHAHAHAHAHAHAAHA.JPG','wb');
--写入数据
while l_pos<l_blob_len loop
dbms_lob.read(l_blob,l_amount,l_pos,l_buffer);
utl_file.put_raw(l_file,l_buffer,true);
l_pos := l_pos + l_amount;
end loop;
utl_file.fclose(l_file);
dbms_output.put_line('恭喜,恭喜。。。。文件写成功!');
end;
/*
文本大对象的写入和读取(clob)。
*/
--写入文本文件第一种方式
declare
tempimg clob;--定义临时变量存放数据
tempdir bfile := bfilename('TEST_DIR','DIV3.html');--非常重要:所有数据都是大写存放的
amount int:=dbms_lob.getlength(tempdir);
src_offset int:=1;
dest_offset int:=1;
csid int:=0;
lc int:=0;
warning int;
begin
insert into test002 values ('第四个文本文件',empty_clob()) returning content into tempimg;
--使用内置的包,给tempimg写入数据
dbms_lob.fileopen(tempdir);--打开指定文件
dbms_lob.loadclobfromfile(tempimg,tempdir,amount,dest_offset,src_offset,csid,lc,warning);
dbms_lob.fileclose(tempdir);--关闭文件
dbms_output.put_line('恭喜你,终于成功了!!!');
commit;
end ;
--写入文本文件第二种方式(通过异常判断文件结束的)
declare
filecontent clob;
input_file utl_file.file_type;
buffer varchar2(2000);
l_pos int := 1;
amount int;
begin
insert into test002 values ('第二个文本数据',empty_clob()) returning content into filecontent;
--打开磁盘文件
input_file := utl_file.fopen('TEST_DIR','DIV3.html','r');
loop
utl_file.get_line(input_file,buffer);
--获取每次读取的长度
amount:=length(buffer);--每次写入的字符长度
exit when amount<=0;
dbms_lob.write(filecontent,amount,l_pos,buffer);
l_pos:=l_pos+amount;
end loop;
utl_file.fclose(input_file);
dbms_output.put_line('文件写入完毕!');
exception
when no_data_found then
dbms_output.put_line('数据已经读取完毕了!');
utl_file.fclose(input_file);
end;
select * from test002
--读取表中的数据,到文件
declare
src clob;
outfile utl_file.file_type;
length integer;
buffer varchar2(8000);
begin
select content into src from test002 where fname='第四个文本文件';
length := dbms_lob.getlength(src);
dbms_lob.read(src,length,1,buffer);
--打开磁盘文件
outfile := utl_file.fopen('TEST_DIR','hahahahhahahahah.html','w',8000);
utl_file.put(outfile,buffer);--写入数据
utl_file.fclose(outfile); --关闭指针
dbms_output.put_line('文件已经写入完毕!');
end;
ORACLE大对象存储的更多相关文章
- JAVA操作ORACLE大对象
一:操作CLOB (1)数据库表结构如下: create table CLOB_TEST ( ID VARCHAR2(5) not null, ...
- 【巨杉数据库Sequoiadb】巨杉⼯具系列之一 | ⼤对象存储⼯具sdblobtool
近期,巨杉数据库正式推出了完整的SequoiaDB 工具包,作为辅助工具,更好地帮助大家使用和运维管理分布式数据库.为此,巨杉技术社区还将持续推出工具系列文章,帮助大家了解巨杉数据库丰富的工具矩阵. ...
- oracle对大对象类型操作:blob,clob,nclob
1.基本介绍 Oracle和plsql都支持lob(large object) 类型,用来存储大数量数据,如图像文件,声音文件等.Oracle 9i realse2支持存储最大为4g的数据,or ...
- Oracle LOB 大对象处理
LOB类型列主要是用来存储大量数据的数据库字段,最大可以存储4G字节的非结构化数据. 一.LOB数据类型分类 1.按存储数据的类型分: ①字符类型: CLOB:存储大量 单字节 字符数据. N ...
- [转帖]Oracle数据库lob大对象数据类型字段总结,值得收藏
Oracle数据库lob大对象数据类型字段总结,值得收藏 原创 波波说运维 2019-07-11 00:02:00 https://www.toutiao.com/i67108943269703357 ...
- Oracle数据库中的大对象(LOB)数据类型介绍
一.LOB数据类型的介绍 大对象(LOB)数据类型允许我们保存和操作非结构化和半结构化数据,如文档.图形图像.视频片段.声音文件和XML文件等.DMBS_LOB 包被设计用于操作 LOB 数据类型.从 ...
- BLOB:大数据,大对象,在数据库中用来存储超长文本的数据,例如图片等
将一张图片存储在mysql中,并读取出来(BLOB数据:插入BLOB类型的数据必须使用PreparedStatement,因为插入BLOB类型的数据无法使用字符串拼写): -------------- ...
- 使用JDBC处理Oracle大数据
一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...
- 利用jdbc处理oracle大数据---大文件和二进制文件
一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...
随机推荐
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解
笔记 1.SpringBoot定时任务schedule讲解 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类 ...
- flutter Draggable Widget拖拽控件
Draggable Widget Draggable控件负责就是拖拽,父层使用了Draggable,它的子元素就是可以拖动的,子元素可以实容器,可以是图片.用起来非常的灵活. 参数说明: data: ...
- DataGrip 2019.1 连接mysql 8.0.16
# 下载mysql Connector/J驱动包 https://dev.mysql.com/downloads/connector/j/ 然后解压到一个目录 # 新建mysql 8.0连接驱动 打开 ...
- PAT 甲级 1072 Gas Station (30 分)(dijstra)
1072 Gas Station (30 分) A gas station has to be built at such a location that the minimum distance ...
- HDU 2089 不要62 数位DP模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 参考博客:https://www.cnblogs.com/HDUjackyan/p/914215 ...
- windows7 + iis7 + fastcgi + php5 + netbeans + xdebug 调试 php
Xdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),可以用来跟踪,调试和分析PHP程序的运行状况. windows7 + iis7 + fastcgi + php5 + netbe ...
- 【git基础】Permission denied (publickey). fatal: Could not read from remote repository
运行以下git命令的时候出现错误 git push -u origin master error The authenticity of host 'github.com (13.250.177.22 ...
- 小程序 支持html富文本吗
详见: https://www.jianshu.com/p/9b9b97b17393
- react——Table组件
/* * 构建数据列 * */ tableColumns = (currentData) => { let group = lodashGroupBy(currentData, 'level1' ...
- sharp.js中文文档
高性能node.js图像处理库,使用libvips库来实现. 英文地址:sharp.pixelplumbing.com/ 中文文档地址:yunlzhang.github.io/sharp-docum…