如何从列中搜索特定值
How to search particular value from column
我有很多 advance_criteria。在 advance_criteria 列中插入所有 select 查询。我只搜索公司代码是 advance_criteria 列中的 17,41。例如,当我尝试执行以下查询时。
with Criteria as
(
select 'SELECT ''Y'' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (17,41)' Advance_Criteria , '1'Col_Id from dual
union all
select 'select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (''01'')' Advance_Criteria , '2'Col_Id from dual
union all
select 'SELECT ''Y'' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (''17'',''41'')' Advance_Criteria , '3'Col_Id from dual
union all
select '
V_RETURN := K_DOCUMENT_TEMPLATE_MANAGEMENT.F_CHECK_FORM_ON_ENDT(P_ENTITY_REFERENCE,P_ENTITY_TYPE, ''17399 0741'');
select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (01, 02, 06, 41, 17)' Advance_Criteria , '4'Col_Id from dual
union all
select 'select DECODE (COUNT(1),0,1,0)
INTO V_RETURN
FROM VW_MIS_QUOTE_POLICIES QP,
where QP.COMPANY_CODE IN (''01'',''02'',''06'',''17'',''41'')
and QP.PRIMARY_STATE_CODE = ''WA''' Advance_Criteria , '5'Col_Id from dual
union all
select 'select 1 from vw_mis_quote_policies
WHERE PROGRAM_CODE IN ( ''29'',''40'', ''46'', ''47'', ''48'')
AND COMPANY_CODE IN (''01'',''02'',''06'',''09'',''29'')' Advance_Criteria , '6'Col_Id from dual
union all
select 'select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (01, 02, 06)' Advance_Criteria , '7'Col_Id from dual
)
select * from Criteria where upper(Advance_Criteria) like upper('%COMPANY_CODE IN (17,41)%')
or
Advance_Criteria like upper('%company_code in (''17'',''41'')%');
我在执行查询后显示了以下输出。
ADVANCE_CRITERIA COL_ID
--------------------------------------------------------------------------------------------
"SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (17,41)" 1
"SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN ('17','41')" 3
期望结果
在 Advance_Criteria 列中搜索 COMPANY_CODE 是 17 和 41
像 col_id 1,3,4,5,6
您可以使用:
select *
from Criteria
where REGEXP_LIKE(
Advance_Criteria,
'COMPANY_CODE\s+IN\s+\((\s*'
|| '(\d+\s*,\s*)*?17\s*,\s*(\d+\s*,\s*)*?41(\s*,\s*\d+)*|'
|| '(\d+\s*,\s*)*?41\s*,\s*(\d+\s*,\s*)*?17(\s*,\s*\d+)*|'
|| q'[('\d+'\s*,\s*)*'17'\s*,\s*('\d+'\s*,\s*)*'41'(\s*,\s*'\d+')*|]'
|| q'[('\d+'\s*,\s*)*'41'\s*,\s*('\d+'\s*,\s*)*'17'(\s*,\s*'\d+')*]'
|| '\s*)\)',
'i'
);
其中,对于示例数据,输出:
ADVANCE_CRITERIA
COL_ID
SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (17,41)
1
SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN ('17','41')
3
select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (01, 02, 06, 41, 17)
4
select DECODE (COUNT(1),0,1,0)
INTO V_RETURN
FROM VW_MIS_QUOTE_POLICIES QP,
where QP.COMPANY_CODE IN ('01','02','06','17','41')
and QP.PRIMARY_STATE_CODE = 'WA'
5
注意:#6 不匹配,因为它不包含 17 或 41。
db<>fiddle here
我有很多 advance_criteria。在 advance_criteria 列中插入所有 select 查询。我只搜索公司代码是 advance_criteria 列中的 17,41。例如,当我尝试执行以下查询时。
with Criteria as
(
select 'SELECT ''Y'' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (17,41)' Advance_Criteria , '1'Col_Id from dual
union all
select 'select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (''01'')' Advance_Criteria , '2'Col_Id from dual
union all
select 'SELECT ''Y'' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (''17'',''41'')' Advance_Criteria , '3'Col_Id from dual
union all
select '
V_RETURN := K_DOCUMENT_TEMPLATE_MANAGEMENT.F_CHECK_FORM_ON_ENDT(P_ENTITY_REFERENCE,P_ENTITY_TYPE, ''17399 0741'');
select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (01, 02, 06, 41, 17)' Advance_Criteria , '4'Col_Id from dual
union all
select 'select DECODE (COUNT(1),0,1,0)
INTO V_RETURN
FROM VW_MIS_QUOTE_POLICIES QP,
where QP.COMPANY_CODE IN (''01'',''02'',''06'',''17'',''41'')
and QP.PRIMARY_STATE_CODE = ''WA''' Advance_Criteria , '5'Col_Id from dual
union all
select 'select 1 from vw_mis_quote_policies
WHERE PROGRAM_CODE IN ( ''29'',''40'', ''46'', ''47'', ''48'')
AND COMPANY_CODE IN (''01'',''02'',''06'',''09'',''29'')' Advance_Criteria , '6'Col_Id from dual
union all
select 'select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (01, 02, 06)' Advance_Criteria , '7'Col_Id from dual
)
select * from Criteria where upper(Advance_Criteria) like upper('%COMPANY_CODE IN (17,41)%')
or
Advance_Criteria like upper('%company_code in (''17'',''41'')%');
我在执行查询后显示了以下输出。
ADVANCE_CRITERIA COL_ID
--------------------------------------------------------------------------------------------
"SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (17,41)" 1
"SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN ('17','41')" 3
期望结果
在 Advance_Criteria 列中搜索 COMPANY_CODE 是 17 和 41 像 col_id 1,3,4,5,6
您可以使用:
select *
from Criteria
where REGEXP_LIKE(
Advance_Criteria,
'COMPANY_CODE\s+IN\s+\((\s*'
|| '(\d+\s*,\s*)*?17\s*,\s*(\d+\s*,\s*)*?41(\s*,\s*\d+)*|'
|| '(\d+\s*,\s*)*?41\s*,\s*(\d+\s*,\s*)*?17(\s*,\s*\d+)*|'
|| q'[('\d+'\s*,\s*)*'17'\s*,\s*('\d+'\s*,\s*)*'41'(\s*,\s*'\d+')*|]'
|| q'[('\d+'\s*,\s*)*'41'\s*,\s*('\d+'\s*,\s*)*'17'(\s*,\s*'\d+')*]'
|| '\s*)\)',
'i'
);
其中,对于示例数据,输出:
ADVANCE_CRITERIA COL_ID SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN (17,41)1 SELECT 'Y' FROM VW_MIS_QUOTE_POLICIES WHERE
ENTITY_REFERENCE = P_ENTITY_REFERENCE and COMPANY_CODE IN ('17','41')3 select * FROM VW_MIS_QUOTE_POLICIES QP where QP.COMPANY_CODE IN (01, 02, 06, 41, 17) 4 select DECODE (COUNT(1),0,1,0)
INTO V_RETURN
FROM VW_MIS_QUOTE_POLICIES QP,
where QP.COMPANY_CODE IN ('01','02','06','17','41')
and QP.PRIMARY_STATE_CODE = 'WA'5
注意:#6 不匹配,因为它不包含 17 或 41。
db<>fiddle here