[英]String operations with regexp
I have the following code : 我有以下代码:
DECLARE
r_blob_data VARCHAR2(4000);
r_length NUMBER;
r_payor_identifer VARCHAR2(100);
clp07_ctx NUMBER;
BEGIN
r_blob_data := 'ISA*00* *00* *ZZ*HCA835EOB *ZZ*BOFAECSUSO *170726*1513*U*00401*835013201*1*P*~\GS*HP*HCA835EOB*BOFAECSUSO*20170726*1513*13201*X*004010X091A1\ST*835*000000547\BPR*C*7.01*C*ACH*CTX*01*061000052*DA*3299975294*3621796494**01*122105744*DA*2500335303*20170728\NTE*ZZZ*SEE OUR WEBSITE @HEALTHCHOICEAZ.COM FOR INFORMATION ON CLAIMS DISPUTERESOLUTION\\DTM*405*20170728\N1*PR*HEALTH
CHOICE ARIZONA\N3*410 NORTH 44TH ST, SUITE 900\N4*PHOENIX*AZ*850080000\N1*PE*FL
AGSTAFF MEDICAL CT DBA*FI*860110232\N3*PO BOX 29435\N4*PHOENIX*AZ*850389435\LX*1
\CLP*10906801*1*22*7.01*0*HM*719281738*22\CLP*10906802*1*23*8.01*0*HM*719281739*
22\NM1*QC*100080033001*CLAIRITY*MICHAEL*E***MR*A77240030\NM1*82*2*FLAGSTAFF MEDI
CAL CT DBA TRAUM*****F*86-0110232\REF*1W*A77240030\AMT*AU*7.01\SVC*HC|93010*22*7
.01**1\DTM*472*20170616\CAS*CO*45*14.58\AMT*B6*7.01\SE*22*000000547\GE*1*13201\I
EA*1*835013201\ ';
select regexp_count(r_blob_data, 'CLP')
into r_length
from dual;
dbms_output.put_line('Number of CLP = '||r_length);
for i in 1 .. r_length
loop
SELECT instr(r_blob_data, 'CLP')
INTO clp07_ctx
FROM dual;
dbms_output.put_line('Clp07_ctx = '||clp07_ctx);
r_payor_identifer := substr(r_blob_data, instr(r_blob_data, '*',clp07_ctx,7)+1,instr(r_blob_data,'*',clp07_ctx,8)-instr(r_blob_data,'*',clp07_ctx,7)-1);
r_payor_identifer := to_char(r_payor_identifer) + to_char(r_payor_identifer);
dbms_output.put_line('CLP07String = '||r_payor_identifer);
end loop;
dbms_output.put_line('CLP07String = '||r_payor_identifer);
END;
What I am trying to do is count the number of occurrences of the CLP segment(a segment is for example, CLP*10906801*1*22*7.01*0*HM*719281738*22) and pull out the values that are equivalent to CLP value 7, in this case for both occurrences the value of 719281738 and get the r_payor_identifer variable output as "719281738719281738". 我想做的是计算CLP段的出现次数(例如,一个段为CLP * 10906801 * 1 * 22 * 7.01 * 0 * HM * 719281738 * 22),并提取与CLP值为7,在这种情况下,这两个值均为719281738,并且将r_payor_identifer变量输出为“ 719281738719281738”。
Any suggestions? 有什么建议么?
Try this REGEXP
pattern : 'CLP[^\\\\]+\\*(\\d+)\\*'
to extract 719281738
and 719281739
from your string. 尝试以下
REGEXP
模式: 'CLP[^\\\\]+\\*(\\d+)\\*'
从您的字符串中提取719281738
和719281739
。
It matches CLP followed by anything other than a \\
and the number between last *..*
它匹配CLP,后跟
\\
以及最后一个*..*
之间的数字*..*
select REGEXP_SUBSTR(r_blob_data, 'CLP[^\\]+\*(\d+)\*' , 1 ,LEVEL, NULL,1) as clp
FROM t
CONNECT BY LEVEL <= REGEXP_COUNT(r_blob_data,'CLP[^\\]+');
Also, to set r_payor_identifer
, use ||
另外,要设置
r_payor_identifer
,请使用||
for concatenation and not +
用于串联而不是
+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.