如何在 oracle 查询中获取字符串的第一行?

Posted

技术标签:

【中文标题】如何在 oracle 查询中获取字符串的第一行?【英文标题】:How to get first line of a string in oracle query? 【发布时间】:2019-06-06 10:24:59 【问题描述】:

到期日:

15/05/12-15/07/12

minimum 15 May 2012 maximum 15 July 2012, the exact period in Charterers option

上面是列中的单元格值,我需要显示该值的唯一第一行,即 15/05/12-15/07/12

To_Char(b.Charter_End_Date, 'DD/MM/RR') || Period_Notice "Expiry Date",

预期结果:

15/05/12-15/07/12

实际结果:

15/05/12-15/07/12

minimum 15 May 2012 maximum 15 July 2012, the exact period in Charterers option

【问题讨论】:

Oracle SQL: Return first line of string using regexp_substr的可能重复 【参考方案1】:

子字符串,最多 CHR(10),可能是您要查找的内容:

SQL> select * From test;

COL
--------------------------------------------------------------------------------
15/05/12-15/07/12

minimum 15 May 2012 maximum 15 July 2012, the exact period in Charterers option


SQL> select substr(col, 1, instr(col, chr(10))) result
  2  from test;

RESULT
--------------------------------------------------------------------------------
15/05/12-15/07/12

SQL>

【讨论】:

以上是关于如何在 oracle 查询中获取字符串的第一行?的主要内容,如果未能解决你的问题,请参考以下文章