zoukankan      html  css  js  c++  java
  • Oracle拆分字符串函数

    1.函数可以将“目标字符串”以“指定字符串”进行拆分,并通过表结构返回结果。代码如下:

    create or replace function FUNC_SPLIT(p_list varchar2,
                                          p_sep  varchar2 in varchar2)
      return type_split
      pipelined is
      l_idx  pls_integer;
      v_list varchar2(4000) := p_list;
    begin
      loop
        l_idx := instr(v_list, p_sep);
        if l_idx > 0 then
          pipe row(substr(v_list, 1, l_idx - 1));
          v_list := substr(v_list, l_idx + length(p_sep));
        else
          pipe row(v_list);
          exit;
        end if;
      end loop;
      return;
    end FUNC_SPLIT;

    如果字符串是逗号隔开的,参数p_sep可以默认写成:p_sep varchar2 := ',';

    2.创建返回类型

    CREATE OR REPLACE TYPE "TYPE_SPLIT"   as table of varchar2(4000)

    3.使用说明

    select * from table(func_split('Hello,split!',','));

    效果图:

    select a.column_value v1,b.column_value v2 from 
    (select * from (select rownum rn,t.* from table(func_split('Hello,Cyrus Joyce',',')) t)) a,
    (select * from (select rownum rn,t.* from table(func_split('Hello,Cyrus Joyce',',')) t)) b
    where a.rn=1 and b.rn=2

    效果图:

  • 相关阅读:
    VUE动画Javascript钩子不生效问题记录
    vue-resource
    shell脚本 回顾 小练习
    mysql 回顾小练习
    jvm调优(二)
    jvm调优(一)
    性能调优笔记(二)
    性能调优笔记(一)
    mac 下 配置appium +ios真机环境
    pycharm中 unittests in xxxx 运行模式
  • 原文地址:https://www.cnblogs.com/smashed/p/4370956.html
Copyright © 2011-2022 走看看