网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 oracle字符拆分函數返回結果集
内容
    oracle不能像mssql那樣支持直接返回表類型,所以要先創建一種自定義類型。這裏用到的是嵌套表(nested table)。
    -- nested table
    create or replace type split_str is table of varchar(100);
    /
    -- function
    create or replace function fn_split
    (
    p_str varchar2,
    p_delimiter varchar2
    )
    return split_str pipelined
    as
    v_str varchar(4000) := p_str;
    v_index number;
    v_sublength number;
    begin
    -- p_delimiter is null
    if p_delimiter is null then
    for x in 1..length(v_str)
    loop
    pipe row(substr(v_str,x,1));
    end loop;
    return;
    end if;
    v_index := instr(v_str,p_delimiter);
    while v_index <> 0
    loop
    pipe row(substr(v_str,1,v_index-1));
    v_sublength := length(v_str) - (v_index + length(p_delimiter) - 1);
    v_str := substr(v_str,-v_sublength,v_sublength);
    v_index := instr(v_str,p_delimiter);
    end loop;
    pipe row(v_str);
    return;
    end;
    /
    -- 調用(第二種方式更好)
    select fn_split('this@@is@@it','@@') from dual;
    select * from table(fn_split('this@@is@@it','@@'));
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/21 8:00:22