我有以下字符串并且只希望输出中的状态名称,请建议我。
'State - Rajasthan,Zone - Jaipur-I,Circle - Circle-P, Jaipur,Ward - Circle-P, jaipur - Ward-2'
所需输出 - 拉贾斯坦邦
我有以下字符串并且只希望输出中的状态名称,请建议我。
'State - Rajasthan,Zone - Jaipur-I,Circle - Circle-P, Jaipur,Ward - Circle-P, jaipur - Ward-2'
所需输出 - 拉贾斯坦邦
根据该示例,您可以考虑以下几个选项:
SQL> with test (col) as
2 (select 'State - Rajasthan,Zone - Jaipur-I,Circle - Circle-P, Jaipur,Ward - Circle-P, jaipur - Ward-2'
3 from dual
4 )
5 select substr(col, instr(col, ' ', 1, 2) + 1,
6 instr(col, ',') - instr(col, ' ', 1, 2) - 1
7 ) state,
8 --
9 replace(substr(col, 1, instr(col, ',') - 1), 'State - ', '') state2,
10 --
11 regexp_substr(col, '\w+', 1, 2) state3
12 from test;
STATE STATE2 STATE3
--------- --------- ---------
Rajasthan Rajasthan Rajasthan
SQL>