首页 > 解决方案 > 如何在 oracle 查询中获取字符串的第一行?

问题描述

到期日:

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

解决方案


子字符串,最多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>

推荐阅读