在 blob Oracle 中查找工作表名称
Find worksheet name in blob Oracle
Oracle table1.data 中有一个 blob test.xlsb 文件。在 test.xlsb 中有一个工作表 'Hello'。但是脚本
SELECT
CASE DBMS_LOB.instr(t.data, UTL_RAW.cast_to_raw('Hello'))
WHEN 0 THEN 'No such line' ELSE 'Okay' END res
FROM table1 t;
return'No such line'。为什么?我们如何解决“*.xlsb 文件是否有包含特定 [sheet.name] 的工作表?”的问题?当然,我们假设我们不能只打开Excel中的文件,看看是否有这样的工作表。
试试这个
select *
from table1
where dbms_lob.instr (t1, -- the blob column of table
utl_raw.cast_to_raw ('Hello'), -- the search string
1, -- starting pointoffset
1 -- the which occurance
) > 0; -- location of text
答案类似于
DECLARE
l_old_file BLOB;
l_new_file BLOB;
l_files apex_zip.t_files;
l_document BLOB;
l_clob CLOB;
l_dest_offsset INTEGER;
l_src_offsset INTEGER;
l_lang_context INTEGER := DBMS_LOB.default_lang_ctx;
l_warning INTEGER;
BEGIN
SELECT t.data INTO l_old_file
FROM table1 t;
-- Get a list of all the file names contained within the zip
l_files := apex_zip.get_files (l_old_file);
-- Loop through all the files adding each one to the new zip
FOR i IN l_files.FIRST .. l_files.LAST
LOOP
l_document := apex_zip.get_file_content (l_old_file, l_files (i));
DBMS_LOB.createTemporary (lob_loc => l_clob, cache => FALSE);
l_dest_offsset := 1;
l_src_offsset := 1;
DBMS_LOB.converttoclob (dest_lob => l_clob,
src_blob => l_document,
amount => DBMS_LOB.lobmaxsize,
dest_offset => l_dest_offsset,
src_offset => l_src_offsset,
blob_csid => DBMS_LOB.default_csid,
lang_context => l_lang_context,
warning => l_warning);
result := INSTR(l_clob, str)
EXIT WHEN res > 0;
l_dest_offsset := 1;
l_src_offsset := 1;
DBMS_LOB.CONVERTTOBLOB (dest_lob => l_document,
src_clob => l_clob,
amount => DBMS_LOB.lobmaxsize,
dest_offset => l_dest_offsset,
src_offset => l_src_offsset,
blob_csid => DBMS_LOB.default_csid,
lang_context => l_lang_context,
warning => l_warning);
END LOOP;
DBMS_OUTPUT.put_line(res);
END;
Oracle table1.data 中有一个 blob test.xlsb 文件。在 test.xlsb 中有一个工作表 'Hello'。但是脚本
SELECT
CASE DBMS_LOB.instr(t.data, UTL_RAW.cast_to_raw('Hello'))
WHEN 0 THEN 'No such line' ELSE 'Okay' END res
FROM table1 t;
return'No such line'。为什么?我们如何解决“*.xlsb 文件是否有包含特定 [sheet.name] 的工作表?”的问题?当然,我们假设我们不能只打开Excel中的文件,看看是否有这样的工作表。
试试这个
select *
from table1
where dbms_lob.instr (t1, -- the blob column of table
utl_raw.cast_to_raw ('Hello'), -- the search string
1, -- starting pointoffset
1 -- the which occurance
) > 0; -- location of text
答案类似于
DECLARE
l_old_file BLOB;
l_new_file BLOB;
l_files apex_zip.t_files;
l_document BLOB;
l_clob CLOB;
l_dest_offsset INTEGER;
l_src_offsset INTEGER;
l_lang_context INTEGER := DBMS_LOB.default_lang_ctx;
l_warning INTEGER;
BEGIN
SELECT t.data INTO l_old_file
FROM table1 t;
-- Get a list of all the file names contained within the zip
l_files := apex_zip.get_files (l_old_file);
-- Loop through all the files adding each one to the new zip
FOR i IN l_files.FIRST .. l_files.LAST
LOOP
l_document := apex_zip.get_file_content (l_old_file, l_files (i));
DBMS_LOB.createTemporary (lob_loc => l_clob, cache => FALSE);
l_dest_offsset := 1;
l_src_offsset := 1;
DBMS_LOB.converttoclob (dest_lob => l_clob,
src_blob => l_document,
amount => DBMS_LOB.lobmaxsize,
dest_offset => l_dest_offsset,
src_offset => l_src_offsset,
blob_csid => DBMS_LOB.default_csid,
lang_context => l_lang_context,
warning => l_warning);
result := INSTR(l_clob, str)
EXIT WHEN res > 0;
l_dest_offsset := 1;
l_src_offsset := 1;
DBMS_LOB.CONVERTTOBLOB (dest_lob => l_document,
src_clob => l_clob,
amount => DBMS_LOB.lobmaxsize,
dest_offset => l_dest_offsset,
src_offset => l_src_offsset,
blob_csid => DBMS_LOB.default_csid,
lang_context => l_lang_context,
warning => l_warning);
END LOOP;
DBMS_OUTPUT.put_line(res);
END;