[英]Oracle function to return the size of a clob in megabytes
I have a table, let's call it attachments. 我有一张桌子,我们称它为附件。
I have an attachment id and the attachment filedata. 我有一个附件ID和附件filedata。 However, unfortunately, when the files are uploaded, the size of the file is never put into a filesize field.....so I have a bit of a predicament.
但是,不幸的是,当文件上传时,文件的大小从未放入文件大小字段中.....所以我有点困境。
Is there a way I could do a query to calculate the size of a. 有没有一种方法可以执行查询来计算a的大小。 a files size in megabytes and b.
文件大小(以兆字节为单位)和b。 to get the total size of all files.
获取所有文件的总大小。
Furthemore, I'm also aware that if I have a huge number of attachments then it'd be a slow query. 此外,我还知道,如果我有大量附件,那将是一个缓慢的查询。 So I'll be caching the query result in my webapp.
因此,我将在Webapp中缓存查询结果。 (refresh every 30mins or so via a cron)
(通过cron每30分钟左右刷新一次)
Any help would be hugely appreciated. 任何帮助将不胜感激。
Thanks! 谢谢!
For those interested, I found the solution: 对于那些感兴趣的人,我找到了解决方案:
create or replace function filesize_in_mb(filedata in blob) return float is
Result float;
begin
select ROUND(((dbms_lob.getlength(filedata)/1024/1024) * 2), 2)
into Result
from dual;
return Result;
end filesize_in_mb;
I'm multiplying by two because the database i'm working with is in utf-16. 我乘以2,因为我正在使用的数据库位于utf-16中。
And to call it: 并称之为:
SELECT filesize_in_mb(a.filedata) as filesize FROM file_attachment a
All rather simple really! 真的很简单! :-)
:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.