问题描述
这两种语法允许从oracle中的字符串获取第二个单词
SELECT REGEXP_SUBSTR('Hello this is an example','\s+(\w+)\s') AS Syntax1,SUBSTR('Hello this is an example',INSTR('Hello this is an example',' ',1,1) + 1,2)
- INSTR('Hello this is an example',1)
) AS Syntax2
FROM dual;
结果:
Syntax1 Syntax2
------- -------
this this
我正在ODI(Oracle数据集成)中工作,这两种语法在ODI中不起作用: 对于ODI,regexp无效,INSTR函数仅接受2个参数
谢谢。
解决方法
然后,您可以两次应用SUBSTR()
函数:
WITH t2(str) AS
(
SELECT SUBSTR( TRIM( str ),INSTR( TRIM( str ),' ') + 1,LENGTH( TRIM(str) ) )
FROM t --> original table
)
SELECT SUBSTR( str,1,INSTR(str,' ') - 1 ) AS extracted_string
FROM t2
extracted_string
----------------
this
如果已安装的 ODI 的版本为 12 + ,那么您也可以使用REGEXP_REPLACE()
,如下所示:
SELECT REGEXP_REPLACE(str,'(\w+)\s(\w+)( .*)','\2' ) AS extracted_string
FROM t
,
我认为它应该支持array_size
我最终使用了这个表达式:
SELECT
SUBSTR (
SUBSTR ('one two three four',INSTR ('one two three four',999999),INSTR (
SUBSTR ('one two three four',' ')
- 1)
FROM DUAL