欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java调用PL/SQL读写blob数据 JavaSQLXML 

程序员文章站 2024-01-06 16:40:04
...
最近项目里需求,需要将每天的数据量写成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;
相关标签: Java SQL XML