java调用PL/SQL读写blob数据

最近项目里需求,需要将每天的数据量写成xml并压缩存储到数据库中,以免每次调用都要进行依次编码并压缩。自然,想到了pl/sql来完成部分业务操作。



建表
create table TEST
(
KEY DATE,
DATAVALUE BLOB
)


create or replace procedure INSERT_BLOB(KEYDATA in VARCHAR2,
BLOBDATA in TEST.Datavalue%TYPE) is
v_lobd TEST.DATAVALUE%TYPE;
v_key TEST.Key%TYPE;
v_count integer;
begin
v_key := to_date(KEYDATA, 'yyyy-mm-dd');
select count(*) into v_count from TEST t where t.key = v_key;
if v_count != 0 then
delete from TEST t where t.key = v_key;
end if;
insert into TEST (key,datavalue) VALUES(v_key, empty_blob()) returning datavalue into v_lobd;
dbms_lob.open(v_lobd,Dbms_Lob.lob_readwrite);
dbms_lob.writeappend(v_lobd,utl_raw.length(BLOBDATA),BLOBDATA);
dbms_lob.close(v_lobd);
commit;
EXCEPTION
when others then
begin
rollback;
end;
end INSERT_BLOB;




create or replace procedure READ_BLOB(STARTDATE in VARCHAR2,
ENDDATE in VARCHAR2,
BLOBDATA out SEARCHDEMOPACKAGE.ResultCursor) is

v_startdate TEST.Key%TYPE;
v_enddate TEST.Key%TYPE;
begin
v_startdate :=to_date(STARTDATE,'yyyy-mm-dd');
v_enddate :=to_date(ENDDATE,'yyyy-mm-dd');
open BLOBDATA for select t.datavalue from TEST t where t.key>=v_startdate and t.key<=v_enddate;
end READ_BLOB;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值