strFieldByName

CREATE OR REPLACE FUNCTION strFieldByName(sRow        VARCHAR2,
                                          sFieldName  VARCHAR2,
                                          sFieldMask   VARCHAR2,
                                          sValueMask  VARCHAR)
  RETURN VARCHAR2 IS
  pvar_i            INT;
  pvar_S            VARCHAR2(4000);
  pvar_Result       VARCHAR2(4000);
  pvar_count        int;
  pvar_LenFieldName integer;
  pvar_sub          varchar2(4000);
  pvar_sRow         varchar2(4000);
  pvar_stmp         varchar2(4000);
  pvar_iCopyCount   int;
BEGIN
  pvar_i    := 0;
  pvar_sRow := sRow;
  pvar_sub  := substr(pvar_sRow, 0, 1);
  if pvar_sub <> nvl(sFieldMask, ';') then
    pvar_sRow := nvl(sFieldMask, ';') || sRow;
  end if;
 
  pvar_sub := substr(pvar_sRow, Length(sRow), 1);
  if pvar_sub <> nvl(sFieldMask, ';') then
    pvar_sRow := pvar_sRow || nvl(sFieldMask, ';');
  end if;
 
  pvar_stmp         := nvl(sFieldMask, ';') || sFieldName ||
                       nvl(sValueMask, '=');
  pvar_LenFieldName := instr(lower(pvar_sRow), lower(pvar_stmp)); --fieldname不分大小写
  if pvar_LenFieldName > 0 then
    pvar_iCopyCount := Instr(pvar_sRow,
                             nvl(sFieldMask, ';'),
                             pvar_LenFieldName + Length(pvar_stmp));
   
    --找到这个field的最后一个;号
    pvar_i := Instr(pvar_sRow, nvl(sValueMask, '='), pvar_iCopyCount + 1);
    while (Instr(pvar_sRow, nvl(sFieldMask, ';'), pvar_iCopyCount + 1) between 1 and
          pvar_i - 1) loop
      pvar_iCopyCount := Instr(pvar_sRow,
                               nvl(sFieldMask, ';'),
                               pvar_iCopyCount + 1);
    end loop;
   
    pvar_Result := substr(pvar_sRow,
                          pvar_LenFieldName + Length(pvar_stmp),
                          pvar_iCopyCount - Length(pvar_stmp) -
                          pvar_LenFieldName);
   
    goto break;
  end if;
  <<break>>
  RETURN pvar_result;
END strfieldbyname;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值