For some reason, I have certain fields in the table that are collections of characters. Scarves of different lengths. Example:
create or replace type t_charray_1 as varray(5) of char(1); create or replace type t_charray_2 as varray(5) of char(2); create or replace type t_charray_3 as varray(5) of char(3); create or replace type t_charray_4 as varray(5) of char(4); create table mytable ( field1 number, field2 t_charray_1, field3 t_charray_3,
In addition, I have a function that returns a string representation (fixed length) of mytable . This function calls other functions that return a string representation of the specified field, entered as a set. Examples:
function to_chr( p_array in t_charray_1, pad_length in number, p_list_length in number ) return char as v_res varchar2(255) := ''; begin for i in 1 .. p_list_length loop if p_array is not null and p_array.exists(i) and p_array(i) is not null then v_res := v_res || rpad(p_array(i), pad_length, ' '); else v_res := v_res || rpad(' ', pad_length, ' '); end if; end loop; return v_res; end to_chr; ------------------------------------------------------------------------------ function to_chr( p_array in t_charray_2, pad_length in number, p_list_length in number ) return char as v_res varchar2(255) := ''; begin for i in 1 .. p_list_length loop if p_array is not null and p_array.exists(i) and p_array(i) is not null then v_res := v_res || rpad(p_array(i), pad_length, ' '); else v_res := v_res || rpad(' ', pad_length, ' '); end if; end loop; return v_res; end to_chr;
Please note that these functions are overloaded versions of each other. The only difference in their signature is the type of the p_array argument.
Also note that the bodies of these functions are identical.
Motivation
I want to remove duplicate code. What are my options?
EDIT I heard about sys.anydata, but never used it. Could this be a solution?
source share