我需要在文本中间附加文本。
1 EX:现有文字为:"Monoclonal Anti-FLAG, Clone 6F7"
结果:"<HIDE>Monoclonal Anti-<HIDE>FLAG, Clone 6F7"
。
2 EX:现有文字为:"Anti-100-KD subunit"
结果:"<HIDE> Anti-</HIDE>100-KD subunit"
我想将<HIDE>
标签附加到Anti和Monoclonal术语即将来临的地方。
select * from table where regexp_like(colnanme, '^(Monoclonal Anti|Anti)')
你能建议我该如何写这个。选择我有书面查询。
答案 0 :(得分:2)
你可以使用替换和喜欢
select replace(colname, 'Anti', '"<HIDE> Anti-</HIDE> )
from table where colname like '%Anti%'
and colname not like 'Monoclonal Anti%';
对于组合情况,您可以使用何时进行铅替换
select case when colname like '%Monoclonal Anti%'
then replace(colname, 'Monoclonal Anti', '"<HIDE> Monoclonal Anti-</HIDE> )
when colname like '%Anti%'
then replace(colname, 'Anti', '"<HIDE> Anti-</HIDE> )
else colname
end
from table where colname like '%Anti%';
答案 1 :(得分:1)
预测的某些正则表达式解决方案。
-- Start test data
with test_data as
(select 'Monoclonal Anti-FLAG, Clone 6F7' as test_string from dual union all
select 'Anti-100-KD subunit' from dual)
-- End test data
select test_string,
REGEXP_REPLACE(test_string,'(Monoclonal Anti-|Anti-)','<HIDE>\1</HIDE>')
from test_data;
"TEST_STRING" "Result"
"Monoclonal Anti-FLAG, Clone 6F7" "<HIDE>Monoclonal Anti-</HIDE>FLAG, Clone 6F7"
"Anti-100-KD subunit" "<HIDE>Anti-</HIDE>100-KD subunit"