zoukankan      html  css  js  c++  java
  • oracle管道函数的用法(一行拆为多行)

    oracle管道函数是一类特殊的函数,oracle管道函数返回值类型必须为集合

    如果需要在客户端实时的输出函数执行过程中的一些信息,在oracle9i以后可以使用管道函数(pipeline function)。

    关键字PIPELINED表明这是一个oracle管道函数,oracle管道函数的返回值类型必须为集合

    --创建一个集合接受返回的值

    1st.create or replace type type_split as table of varchar2(4000);

    --创建管道函数

    create or replace function split(p_string varchar2, p_sep varchar2 := ',') return type_split pipelined
    --dbms_output输出的信息,需要在服务器执行完整个函数后一次性的返回给客户端
    --pipelined 表明这是一个管道函数,oracle管道函数的返回值类型必须为集合
    --PIPE ROW语句被用来返回该集合的单个元素
    as

    v_string varchar2(4000) := p_string;
    idx Number;

    begin
    loop
    --idx为第一个,所在的位置
    idx := instr(v_string, p_sep);
    if idx > 0 then
    --,前面的数据加入Row/,后面的数据为下个循环使用的字符串
    pipe row(substr(v_string, 1, idx - 1));
    v_string := substr(v_string, idx + length(p_sep));
    else
    exit;
    end if;
    end loop;
    --执行完后需return
    return ;
    end;

    test:

    select a.cust_po,b.column_value proqepi from
    (
      select cust_po,proqepi

      from cux_custpo_info_t

      where cust_po='PX90806001-4'
    ) a,(table(split(a.proqepi,','))) b

    测试成功。

  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    Swift
    nineOldAnimation 应用
    Android 编程下 Touch 事件的分发和消费机制
    用Gradle 构建android程序
    CygWin模拟Linux环境进行Ant批量打包
    UML类图与类的关系详解
  • 原文地址:https://www.cnblogs.com/hong-dan/p/11429342.html
Copyright © 2011-2022 走看看