How would you write a SQL query to get the size of blob in a more human readable form? The example would be something like a large word document is being stored in a blob on a table. I would want to execute something like:
select fnc_getReadableSize(documents.doc) from documents where id = ?
output: 23.4 MB
The 'readable' part is what I should have emphasized more. Here is what I put together for now.
WITH file_sizes AS
(SELECT 1048576 MEGABYTE, 1024 KILOBYTE,
DBMS_LOB.GETLENGTH (BLOB_COLUMN) byte_size
FROM BLOB_COLUMN)
SELECT (CASE TRUNC (byte_size / MEGABYTE)
WHEN 0
THEN TO_CHAR ((byte_size / KILOBYTE), '999,999') || ' KB'
ELSE TO_CHAR ((byte_size / MEGABYTE), '999,999.00') || ' MB'
END
) display_size
FROM file_sizes
Output:
DISPLAY_SIZE
--------------
1.88 MB
433 KB
540 KB
333 KB
1.57 MB
1.17 MB
SELECT DBMS_LOB.GETLENGTH(COLUMN_NAME) FROM DOCUMENTS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With