ORACLE_截取字符串中指定的字符和值

CREATE OR REPLACE FUNCTION splitTTCreateDescription
(
  tableField  VARCHAR2,  -- field in the tbl_wftt_ttcreate
  description VARCHAR2,  -- description from tbl_wftt_ttcreate
  key         VARCHAR2   -- field in the description
)
  RETURN VARCHAR2
IS
  firstPoint  INT; -- index where the key appeared
  secondPoint INT; -- index where the newline symbol appeared
  outStr   VARCHAR2(1000); -- return value
  otherStr VARCHAR2(1000); -- substring exclude the 'firstpoint'

BEGIN
  -- if the 'tableField' does not empty, return 'tableField'
  IF (tableField IS NOT NULL) THEN
    RETURN tableField;
  END IF;
  -- if the key does not exist, return empty
  IF (INSTR(description, key || '=') = 0) THEN
    RETURN '';
  END IF;
  -- if the key equals the 'Location', no need to get the 'secondPoint'
  IF (key <> 'Location') THEN
    firstPoint  := INSTR(description, key || '=') + LENGTH(key) + 1;
    otherStr    := TRIM(substr(description, firstPoint));
    secondPoint := INSTR(otherStr, CHR(10));
    outStr      := TRIM(SUBSTR(otherStr, 0, secondPoint));
  ELSE
    firstPoint := INSTR(description, key || '=') + LENGTH(key) + 1;
    outStr     := TRIM(substr(description, firstPoint));
  END IF;
  -- remove the newline symbol
  RETURN REPLACE(outStr, CHR(10), '');
END;
/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值