zoukankan      html  css  js  c++  java
  • 模拟java的split函数,分割字符串,类似于java的split方法

      本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处

      http://www.cnblogs.com/king-xg/p/6362037.html

    /*自定义oracle的分割函数*/
    /*定义一个type,用户接收返回的数据集合类型*/
    create or replace type splitType as table of varchar2(4000);

    /*
    参数1: 被分割的字符串
    参数2:分割字符串,默认是英文逗号
    */
    create or replace function split_str(str varchar2, split_char varchar2:=',')
    return splitType pipelined
    is
    idx number(4);
    orgin_str varchar2(1000):=str;
    temp_str varchar2(1000);
    split_length number:=0;
    begin
    -- 判断
    select nvl(length(split_char),0) into split_length from dual;
    if  split_length=0 then
      pipe row(str);
      return;
    end if;

    select nvl(length(str),0) into split_length from dual;
    if  split_length=0 then
      pipe row(str);
      return;
    end if;

    idx:=instr(orgin_str,split_char);
    loop
    exit when idx=0;
    temp_str:=substr(orgin_str,1,idx-1);
    pipe row(temp_str);
    orgin_str:=substr(orgin_str,idx+1);
    idx:=instr(orgin_str,split_char);
    end loop;
    pipe row(orgin_str);
    return;
    end;

    /**测试**/

    select * from table(split_str('king,arise',','));

  • 相关阅读:
    javascript对话框
    重构之美-走在Web标准化设计的路上[复杂表单]
    xhtml标准下的height:100%
    javascript简洁的LightBox
    Web标准学习书籍推荐
    Email
    jQuery插件Cookie
    Linq to sql 简单性能差异指引 2 (转)
    jQuery Impromptu
    UI
  • 原文地址:https://www.cnblogs.com/king-xg/p/6362037.html
Copyright © 2011-2022 走看看