Created
December 16, 2013 19:58
-
-
Save pshapoval/7993306 to your computer and use it in GitHub Desktop.
Oracle PL-SQL function to convert bytes into KB, MB and so on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function format_size(p_size IN NUMBER) | |
return VARCHAR2 | |
IS | |
v_i number; | |
type array_t is varray(3) of varchar2(10); | |
v_array array_t := array_t(' Bytes', ' KB', ' MB'); | |
BEGIN | |
v_i := floor(log(1024, p_size)); | |
return to_char(round(p_size/power(1024, v_i), 2))||v_array(v_i+1); | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment