我需要取括号([])中的值: 示例:
[TextValue][WINDOM][Camry]
我的代码:
select substr('[TextValue][WINDOM][Camry]',
instr('[TextValue][WINDOM][Camry]', '[',1,2),
instr('[TextValue][WINDOM][Camry]', ']',1,2) )
from dual
期望的结果:WINDOM
答案 0 :(得分:2)
第三个参数是长度:
with s as (select '[TextValue][WINDOM][Camry]' as Text from Dual)
select substr(substr(s.Text, instr(s.Text, '[', 1, 2) + 1), 1, instr(substr(s.Text, instr(s.Text, '[', 1, 2) + 1), ']') - 1)
from s
答案 1 :(得分:1)
你几乎就在那里,但SUBSTR
有签名SUBSTR( string, start, length )
:
Oracle 11g R2架构设置:
CREATE TABLE test_data ( value ) AS
SELECT '[TextValue][WINDOM][Camry]' FROM DUAL;
查询1 :
SELECT SUBSTR(
value,
open_bracket2 + 1,
close_bracket2 - open_bracket2 - 1
) AS bracket2
FROM (
SELECT value,
INSTR( value, '[', 1, 2 ) AS open_bracket2,
INSTR( value, ']', 1, 2 ) AS close_bracket2
FROM test_data
)
<强> Results 强>:
| BRACKET2 |
|----------|
| WINDOM |