• SQL 语句(四)自定义函数


    Create Table henry_test (a varchar2(10),b int);
    Insert Into henry_test values ('aa',1);
    Insert Into henry_test values ('bb',1);
    Insert Into henry_test values ('cc',1);
    Insert Into henry_test values ('dd',2);
    Insert Into henry_test values ('ee',2);
    Insert Into henry_test values ('ff',3);
    Insert Into henry_test values ('gg',3);
    Insert Into henry_test values ('hh',3);
    Commit;
    ------------------------------------
    create or replace function f_henry_ConcatRowsByColumn(
    Column2Value in Varchar2,  --分组该列的值
    ColumnName1 in Varchar2,  --要连接的列名
    ColumnName2 in Varchar2,  --用来做分组依据的列名
    TableName  in Varchar2  --表名
    )
      return varchar2 is
      v_Result varchar2(32767);
      type cur_type is ref cursor;
      myCur cur_type;
      v_Column1Value varchar2(4000);
    begin
      Open myCur for 'Select '||ColumnName1||' From '||TableName||' Where '||ColumnName2||' = '||Column2Value;
      Loop
        Fetch myCur Into v_Column1Value;
        Exit When myCur%notfound;
        v_Result:=v_Result||v_Column1Value||',';
      End Loop;
      Close myCur;
      return(v_Result);
    end f_henry_ConcatRowsByColumn;

  • 相关阅读:
    Luogu 4841 城市规划
    Luogu 4721 【模板】分治 FFT
    Luogu 4091 [HEOI2016/TJOI2016]求和
    Luogu 3723 [AH2017/HNOI2017]礼物
    FFT笔记
    Luogu 4900 食堂
    Luogu 4155 [SCOI2015]国旗计划
    Luogu 4069 [SDOI2016]游戏
    Luogu 4254 [JSOI2008]Blue Mary开公司
    Luogu 4251 [SCOI2015]小凸玩矩阵
  • 原文地址:https://www.cnblogs.com/HondaHsu/p/808226.html
Copyright © 2020-2023  润新知