【问题标题】:Extract the second word from a string in ODI Expression从 ODI 表达式中的字符串中提取第二个单词
【发布时间】:2020-09-17 18:21:38
【问题描述】:

这两种语法允许从 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, 
              INSTR('Hello this is an example', ' ', 1, 2) 
              - INSTR('Hello this is an example', ' ', 1)
       ) AS syntax2 
  FROM dual;

结果:

syntax1  syntax2
-------  -------
this     this

我在 ODI(oracle 数据集成)中工作,这两种语法在 ODI 中不起作用: 对于 ODI,正则表达式无效,INSTR 函数只接受 2 个参数

您能建议我一个可以在 ODI 中使用的解决方案吗?

谢谢。

【问题讨论】:

    标签: sql oracle substring oracle-data-integrator


    【解决方案1】:

    我觉得应该支持' [[:alpha:]]+ '

    【讨论】:

      【解决方案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
      

      Demo

      【讨论】:

      • 我正在开发 ODI 12.1.3,不接受正则表达式。感谢您的回答,当我在过程 ODI 中使用它时可以,但我需要表达属性
      • Hı @Ruby 我知道它不支持 REGEXP_SUBSTR(),但应该支持 REGEXP_REPLACE()。您是否尝试过答案中的这两种情况..?
      【解决方案3】:

      我终于用了这个表达方式:

      SELECT 
                SUBSTR (
                   SUBSTR ('one two three four',
                           INSTR ('one two three four', ' ') + 1,
                           999999),
                   0,
                     INSTR (
                        SUBSTR ('one two three four',
                                INSTR ('one two three four', ' ') + 1,
                                999999),
                        ' ')
                   - 1)
        FROM DUAL       
      
           
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-09
        • 2020-04-04
        • 2021-09-12
        • 2016-02-24
        • 2015-05-08
        • 2019-03-18
        • 1970-01-01
        相关资源
        最近更新 更多