-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathF_LIST_TO_CSV.sql
53 lines (36 loc) · 1.65 KB
/
F_LIST_TO_CSV.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
create or replace function F_LIST_TO_CSV ( I_LIST in T_STRING_LIST
, I_SEPARATOR in varchar2 := ','
, I_ENCLOSED_BY in varchar2 := null
) return varchar2 is
/********************************************************************************************************************
The F_LIST_TO_CSV just creates a separator/delimiter separated string from the input
optionally enclosed by encloser.
Parameters:
-----------
I_LIST the string list to transform to CSV string
I_SEPARATOR the field separator/delimiter
I_ENCLOSED_BY the optional encloser (both left and right)
Samples:
-------
F_LIST_TO_CSV ( T_STRING_LIST( '1', '2', '3,1415' ), ',' )
F_LIST_TO_CSV ( T_STRING_LIST( '1', '2', '3,1415' ), ',', '"' )
Results:
-------
1,2,3,1415
"1","2","3,1415"
History of changes
yyyy.mm.dd | Version | Author | Changes
-----------+---------+----------------+-------------------------
2017.01.06 | 1.0 | Ferenc Toth | Created
********************************************************************************************************************/
V_CSV_STRING varchar2( 32000 );
V_SEPARATOR varchar2( 32000 );
begin
for L_I in 1..I_LIST.count
loop
V_CSV_STRING := V_CSV_STRING || V_SEPARATOR || I_ENCLOSED_BY || I_LIST( L_I ) || I_ENCLOSED_BY;
V_SEPARATOR := nvl(I_SEPARATOR,',');
end loop;
return V_CSV_STRING;
end;
/