Home > Database > Mysql Tutorial > body text

array to csv

WBOY
Release: 2016-06-07 14:54:58
Original
1262 people have browsed it

将字符数组,转化成CSV的格式 PL/SQL CSV type t_str_array as table of varchar2(4000);function array_to_csv (p_values in t_str_array, p_separator in varchar2 := g_default_separator) return varchar2as l_value varchar2(32000); l_returnvalue varc

将字符数组,转化成CSV的格式 PL/SQL CSV
type t_str_array as table of varchar2(4000);
function array_to_csv (p_values in t_str_array,
                       p_separator in varchar2 := g_default_separator) return varchar2
as
  l_value       varchar2(32000);
  l_returnvalue varchar2(32000);
begin

  /*

  Purpose:      convert array of values to CSV

  Remarks:

  Who     Date        Description
  ------  ----------  --------------------------------
  MBR     31.03.2010  Created
  fartpig 07.03.2011  noted
  */
  --遍历值 数组
  for i in p_values.first .. p_values.last loop    
    l_value := p_values(i);
    --如果其中包含了 分割符号,
    if instr(l_value, p_separator) > 0 then
      --使用 双引号 将其包括起来
      l_value := '"' || l_value || '"';
    end if;
    --如果 是第一次 赋值
    if l_returnvalue is null then
      --直接 赋值
      l_returnvalue := l_value;
    else
      --使用 分隔符, 进行相应的 值的分割
      l_returnvalue := l_returnvalue || p_separator || l_value;
    end if;
  end loop;

  return l_returnvalue;

end array_to_csv;
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template