- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从我们的 Oracle 11g (11.2.0.3) 系统导出 BLOB。该过程适用于小于 32,767 字节的 BLOB(JPG 照片)。我能够使用 dbms_log.read 和 utl_file.put_raw 在 5 秒内将约 4000 张照片导出到数据库服务器上的本地目录。如果文件超过读取缓冲区的 32,767 字节限制,这就是性能问题开始的地方。我看过关于确切性能问题的类似帖子,但所提供的解决方案已经过研究但没有成功。根据监控工具,导出过程中CPU、I/O、内存没有压力。我试图理解为什么必须以 32,767 字节的增量将较大的 BLOB(它们的大小都小于 100K)与 32,767 字节以下的 BLOB 相比,导出速度如此之快。导出大型 BLOB 时,每个文件最多可能需要 15 秒才能导出。
Related Post of slow blob extraction
Related Post of BLOB export tuning
有没有人遇到过文件大于 32,767 字节的 BLOB 导出缓慢?
DECLARE
CURSOR cur_photo IS
select substr(c.custnum, -7, length(c.custnum)) custnum,
cp.cust_id,
cp.photo
from customer c
inner join customer_photo cp
on c.cust_id = cp.cust_id
inner join customer_def_grp_value cdv
on c.cust_id = cdv.cust_id;
select_sql varchar2(225);
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount PLS_INTEGER := 32767;
l_pos PLS_INTEGER := 1;
l_blob BLOB;
l_blob_len PLS_INTEGER;
l_filename varchar2(225);
error_number varchar2(225);
error_message varchar2(225);
BEGIN
--dbms_output.put_line('Starting at: ' || to_char(systimestamp, 'DD-MON-YYYY HH:MI:SS.FF6'));
--DBMS_OUTPUT.ENABLE (buffer_size => NULL);
FOR custphoto IN cur_photo LOOP
--dbms_output.put_line('In the loop ' || custphoto.cust_id);
select_sql := 'SELECT photo FROM customer_photo WHERE cust_id = :cust_id';
--dbms_output.put_line('Statement: ' || select_sql);
EXECUTE IMMEDIATE select_sql INTO l_blob using custphoto.cust_id;
l_blob_len := DBMS_LOB.getlength(l_blob);
--dbms_output.put_line('BLOB length: ' || l_blob_len);
-- Set the filename
l_filename := custphoto.custnum || '.jpg';
--dbms_output.put_line('Filename: ' || l_filename);
-- Open the destination file.
l_file := UTL_FILE.fopen('jpeg', l_filename, 'wb', 32767);
--dbms_output.put_line('Start Export at: ' || to_char(systimestamp, 'DD-MON-YYYY HH:MI:SS.FF6'));
IF l_blob_len < 32767 then
--dbms_output.put_line('BLOB < 32767 bytes');
DBMS_LOB.read(l_blob, l_blob_len, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
ELSE -- write in pieces
--dbms_output.put_line('BLOB >= 32767 bytes');
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;
END IF;
-- Close the file.
UTL_FILE.fclose(l_file);
-- Reset the pos for the next jpg file
l_pos := 1;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
-- Close the file if something goes wrong.
error_number := sqlcode;
error_message := substr(sqlerrm, 1, 100);
dbms_output.put_line('Error Number: ' || error_number);
dbms_output.put_line('Error Message: ' || error_message);
utl_file.fclose_all;
RAISE;
END;
提前感谢您对 BLOB 导出的任何见解。
最佳答案
您还需要重置 l_amount
。
l_amount := 32767;
dbms_lob.read 的第二个参数是一个IN OUT
参数。
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_lob.htm#i999170
DBMS_LOB.READ (
lob_loc IN BLOB,
amount IN OUT NOCOPY INTEGER,
offset IN INTEGER,
buffer OUT RAW);
如果你不走运,它只剩下 1 个字节可供读取,然后你将逐字节遍历下一个大 blob:
amount
Number of bytes (for BLOBs) or characters (for CLOBs) to read, or number that were read.
我已经完成了全部作业,可以重现缓慢的性能。我创建了一些测试数据,如下所述:Prepare test data on Oracle with blob column
然后我用自己的测试程序试了一下:
create or replace directory outdir as '/home/oracle/pngs';
set serveroutput on
declare
l_file utl_file.file_type;
l_buffer RAW(32767);
l_amount PLS_INTEGER := 32767;
l_pos PLS_INTEGER := 1;
l_blob_len PLS_INTEGER;
begin
--l_amount := 1; -- this wrecked the performance
for c in (select * from demo.blob_test) loop
l_file := UTL_FILE.fopen('OUTDIR', 'blob'||c.id||'.png', 'wb', 32767);
l_blob_len := DBMS_LOB.getlength(c.data);
IF l_blob_len < 32767 then
dbms_output.put_line(systimestamp||' BLOB < 32767 bytes');
DBMS_LOB.read(c.data, l_blob_len, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
dbms_output.put_line(systimestamp||' done');
ELSE
dbms_output.put_line(systimestamp||' BLOB >= 32767 bytes len '||l_blob_len);
WHILE l_pos < l_blob_len LOOP
--dbms_output.put_line(systimestamp||' l_pos '||l_pos||' l_amount '||l_amount);
DBMS_LOB.read(c.data, l_amount, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
dbms_output.put_line(systimestamp||' done');
END IF;
l_pos := 1;
l_amount := 32767; -- this handled it
utl_file.fclose(l_file);
end loop;
end;
关于performance - 对于大于 32kb 的文件,BLOB 导出速度很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16923374/
我不太确定为什么较大字符串(“cat”和“dog”)的答案不一致。我正在用链接列表和模板的使用做一些事情。我的好奇心促使我修改模板和函数重载。如果有人能解释发生了什么,我将不胜感激。谢谢你。 #inc
目前我必须编写这样的查询 SELECT * FROM table WHERE value1 > 5000 OR value2 > 5000 OR value3 > 5000 OR value4 > 5
我想创建一个如下所示的查询,但我不确定如何正确编码, 我希望它在开始时间的 1 小时内返回所有预订,这是我想出的: SELECT BookingId, StartTime FROM Booking W
这个问题已经有答案了: How to check if a number is between two values? (12 个回答) 已关闭 6 年前。 我目前正在 Codecademy 上学习
我想验证用户输入。如果用户输入的数字大于 3,则应抛出错误“Too high”,如果小于 0.15,则应抛出“Too low”错误。如果它在 3 到 0.15 之间,那么它应该显示“好的”。 我的代码
我有一个拖动脚本,我在其中拖动 div.slider,我正在跟踪 div.slider 的“左”值,并在它大于 68 时让它淡出,但问题是它当它达到 6 而不是 68 时淡出。如果我将数字更改为 85
是否有一种常见的模式如何在数据库(postgresql)中存储这样的条件,然后以简单的方式从数据库中获取这些数据,并在前端将其与我们在前端的值 SE 进行比较(以获得正确的“值” "): condit
如何大于/小于内部工作 如果我将 5 与 100 与 5 与 2,147,483,647 (Integer.MAX_VALUE) 进行比较,性能会受到多大影响 5 < 100 and 5 < Inte
当我运行此查询时它有效 SELECT sum( amount ) AS balance FROM balance WHERE amount >= 100 但是当我想过滤用户 ID 时,它返回 NULL
我有下表: account(id, balance, bank_branch) 我想选择账户余额大于其 bank_branch 平均余额的所有账户 我试过了 Select id from accoun
你们有没有人知道如何搜索所有大于指定数字的数字? 例如:所有单据编号>65 我试过这样:documentNumber: [65 TO *] 但我收到异常,因为 lucene 期望解析一个没有 * 的数
我正在使用 Prolog 算法,并且有一个生成抽象语法树的程序,例如 plus(num(1),num(2))这只是 1+2 .这是通过使用 DCG 来完成的。在这个例子中 plus(num(1),nu
是否使用 Sin(720) 或 Cos(1440)(以度为单位的角度)? 无论是在计算机编程中还是在任何其他情况下? 一般来说,是否有任何角度的 Sin/Cosine/Tan 使用 大于360? 在物
我发现了一些与此相关的问题,但没有一个真正回答了我的问题。 我有一个像这样的表格文件: 2 10610 0 0 0 0.0105292 2 10649 0 0 0
我是 Prolog 的新手,我正在尝试解决这个练习: Define a predicate greater_than/2 that takes two numerals in the notation
我想选择具有出现次数的不同键,此查询似乎有效: SELECT ItemMetaData.KEY, ItemMetaData.VALUE, count(*) FROM ItemMetaData GROU
我需要存储和使用大于 ULLONG_MAX 的数值。 我需要对这些值进行算术运算,所以我认为存储为 char** 不是一个选项。 在这些情况下,有没有办法动态创建额外的 long 前缀? 谢谢大家。根
我是 Prolog 的新手,我正在尝试解决这个练习: Define a predicate greater_than/2 that takes two numerals in the notation
处理已知大小但大于 64 位的位掩码(即执行所有位操作)的最有效的数据结构是什么? 字节[]? 大整数?完全是别的东西吗? 需要与 Java 7 兼容,并且对于诸如此类的事情应该很快(或者至少与合理预
编辑:抱歉进行了许多编辑。我自己都忘记写了什么了。 我使用 JPanel,将 BoxLayout 作为 JFrame 的根面板。我向此根面板添加了另外两个面板:带有 FlowLayou 的 Butto
我是一名优秀的程序员,十分优秀!