oracle string util package
-- 1. create type as object
create or replace type ty_col01 as object
(
col01 varchar2(200)
);
-- 2. create type as table
create or replace type ty_tbl01 as table of ty_col01;
-- 3. create package
create or replace package pkg_string as
/*********************************************
Description.
pkg_string sting util
Parameter.
Create.
2018.12.28 hsy
Modify.
**********************************************/
function fn_stringtoarray
(
ps_str in varchar2,
ps_group in integer
) return ty_tbl01;
function fn_stringtoarray
(
ps_str in varchar2,
ps_separ in varchar2
) return ty_tbl01;
end;
-- 4. create package body
create or replace package body pkg_string as
/*********************************************
Description.
fn_stringtoarray
fn_stringtoarray
Parameter.
Create.
2018.12.28 hsy
Modify.
**********************************************/
/*--- 문자열, 자리수로 자르기 ---*/
function fn_stringtoarray
(
ps_str in varchar2,
ps_group in integer
) return ty_tbl01 as
ty_rtn ty_tbl01;
begin
select ty_col01(code_list)
bulk collect
into ty_rtn
from (select substr(ps_str, 1 + ((level - 1) * ps_group), ps_group) as code_list
from dual
connect by level <= (length(ps_str) / ps_group) + 1)
where code_list is not null;
return ty_rtn;
end;
/*--- 문자열, 구분자로 자르기 ---*/
function fn_stringtoarray
(
ps_str in varchar2,
ps_separ in varchar2
) return ty_tbl01 as
ty_rtn ty_tbl01;
begin
select ty_col01(code_list)
bulk collect
into ty_rtn
from (select regexp_substr(ps_str, '[^' || '' || ps_separ || '' || ']+', 1, level) as code_list
from dual
connect by instr(ps_str, ps_separ, 1, level - 1) > 0)
where code_list is not null;
return ty_rtn;
end;
end;
-- 5. select
select *
from table(pkg_string.fn_stringtoarray('1234567890', 1));
select *
from table(pkg_string.fn_stringtoarray('1;2;3;4;5;67890', ';'));
'Oracle(DB관련)' 카테고리의 다른 글
oracle 비율로 배분 후 나머지 마지막에 합산 (0) | 2019.12.02 |
---|---|
oracle alert log 파일 조회 diy$alert (0) | 2019.11.08 |
oracle audit (0) | 2018.11.22 |
user_source, sys.all_objects (0) | 2018.11.05 |
Oracle Bulk SQL and Bulk Binding (bulk collect) (0) | 2018.06.12 |