Home > Database > Mysql Tutorial > Oracle反转倒置函数

Oracle反转倒置函数

WBOY
Release: 2016-06-07 16:08:41
Original
1383 people have browsed it

Oracle提供了一个反转倒置函数reverse,但此函数不能分组倒置,本文提供了一个即可分组倒置的函数,如下所示:

Oracle提供了一个反转倒置函数reverse,但此函数不能分组倒置,,本文提供了一个即可分组倒置的函数,如下所示:

CREATE OR REPLACE FUNCTION REVERSE_F(p_str VARCHAR2, p_delimiter VARCHAR2:='')
  RETURN VARCHAR2 IS
  v_return VARCHAR2(4000);
  vp_str  VARCHAR2(4000) := p_str;
  v_idx    number;
  vp_len  number := length(p_delimiter);
BEGIN
  if (p_delimiter is null) then
    select reverse(p_str) into v_return from dual;
  else
    loop
      v_idx := instr(vp_str, p_delimiter);
      if (v_idx = 0) then
        v_return := vp_str || v_return;
        exit;
      elsif (v_idx = 1) then
        v_return := substr(vp_str, 1, vp_len) || v_return;
        vp_str  := substr(vp_str, vp_len + 1);
      else
        v_return := substr(vp_str, 1, v_idx - 1) || v_return;
        vp_str  := substr(vp_str, v_idx);
      end if;
    end loop;
  end if;
  RETURN v_return;
END REVERSE_F;

效果图

Oracle函数之GREATEST函数详解实例

Oracle函数之单行转换函数

生成动态前缀且自增号码的Oracle函数

Oracle函数之Replace()

Oracle函数大全

Oracle函数之case和decode的用法区别及性能比较

本文永久更新链接地址:

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