• [转载]Oracle Str Split Function


    create or replace type tb_strSplit  as table of varchar2(4000);

    create or replace function to_table(pv_str varchar2,pv_split varchar2) return tb_strSplit
    as
      ltab tb_strSplit := tb_strSplit();
      pos integer := 0;
      ls varchar2(4000) := pv_str;
    begin
      pos := instr(ls,pv_split);
      while pos > 0 loop
        ltab.extend;
        ltab(ltab.count) := substr(ls,1,pos - 1);
        ls := substr(ls,pos + length(pv_split));
        pos := instr(ls,pv_split);
      end loop;
      ltab.extend;
      ltab(ltab.count) := ls;
      return ltab;
    end;


    set serverout on
    declare
    aa tbl_str;
    begin
    aa := to_table('a|||b|||c','|||');
    for i in 1..aa.count loop
            dbms_output.put_line(aa(i));
    end loop;
    end;
    /

    ----------------------------------------------------------

    CREATE OR REPLACE function strToTb(inVStr in string,inStrSplit in varchar) return tb_strSplit PIPELINED
    as
    v_tmp varchar2(4000);
    v_element varchar2(4000);
    begin

    v_tmp := inVStr;
    while instr(v_tmp,inStrSplit)>0 loop
       v_element := substr(v_tmp,1,instr(v_tmp,inStrSplit)-1);
       v_tmp := substr(v_tmp,instr(v_tmp,inStrSplit)+length(inStrSplit),length(v_tmp));
       pipe row(v_element);
    end loop;

    pipe row(v_tmp);

    return;
    end strToTb;
    /

    select * from table(strToTb('a|||b|||c','|||'));

  • 相关阅读:
    生成器,迭代器
    装饰器
    作业修改配置文件 查询,添加
    continue 和 break的实例
    作业,修改haproxy配置文件
    zabbix分布式部署
    zabbix全网监控介绍
    nginx+tomcat9+memcached-session-manager会话共享
    tomcat管理登陆界面无法进行登陆
    JAVA与tomcat部署
  • 原文地址:https://www.cnblogs.com/RobotTech/p/1911124.html
Copyright © 2020-2023  润新知