Skip to content

Instantly share code, notes, and snippets.

@pshapoval
Created December 16, 2013 19:58
Show Gist options
  • Save pshapoval/7993306 to your computer and use it in GitHub Desktop.
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
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