There are number of ways to split comma separated values. This is very simple method to separate the comma separated or any other separated string. you can change the delimiter as per your requirement. This method have a limitation that string can not exceed the 4000 characters.
if you want a functionality more than 4000 characters, Please go for long input values also use packages instead of procedures, because functions do not support long parameter type.
Please comment for any issues/Questions.
- CREATE OR REPLACE FUNCTION FNC_SPLIT( p_list varchar2, p_del varchar2 := ',') return tp_split_tbl pipelined
- is
- l_idx pls_integer;
- l_list varchar2(32767) := p_list;
- begin
- loop
- l_idx := instr(l_list,p_del);
- if l_idx > 0 then
- pipe row(substr(l_list,1,l_idx-1));
- l_list := substr(l_list,l_idx+length(p_del));
- else
- pipe row(l_list);
- exit;
- end if;
- end loop;
- return;
- end ;
How to call function:
- SELECT NVL(COLUMN_VALUE, '') emp_name
- FROM TABLE(FNC_SPLIT(comma_separated_string, ','))
The above function returns the pipeline table, you can use a temporary table to insert the values.
No comments:
Post a Comment