<i id='9wmp8'><tr id='9wmp8'><dt id='9wmp8'><q id='9wmp8'><span id='9wmp8'><b id='9wmp8'><form id='9wmp8'><ins id='9wmp8'></ins><ul id='9wmp8'></ul><sub id='9wmp8'></sub></form><legend id='9wmp8'></legend><bdo id='9wmp8'><pre id='9wmp8'><center id='9wmp8'></center></pre></bdo></b><th id='9wmp8'></th></span></q></dt></tr></i><div id='9wmp8'><tfoot id='9wmp8'></tfoot><dl id='9wmp8'><fieldset id='9wmp8'></fieldset></dl></div>

    1. <small id='9wmp8'></small><noframes id='9wmp8'>

      <legend id='9wmp8'><style id='9wmp8'><dir id='9wmp8'><q id='9wmp8'></q></dir></style></legend>

        • <bdo id='9wmp8'></bdo><ul id='9wmp8'></ul>
        <tfoot id='9wmp8'></tfoot>
      1. 如何在 Oracle SQL 中选择特定字符的子字符串?

        时间:2023-09-19
      2. <small id='ZXJ9v'></small><noframes id='ZXJ9v'>

        <tfoot id='ZXJ9v'></tfoot>
          <tbody id='ZXJ9v'></tbody>
          <bdo id='ZXJ9v'></bdo><ul id='ZXJ9v'></ul>
            <legend id='ZXJ9v'><style id='ZXJ9v'><dir id='ZXJ9v'><q id='ZXJ9v'></q></dir></style></legend>

                1. <i id='ZXJ9v'><tr id='ZXJ9v'><dt id='ZXJ9v'><q id='ZXJ9v'><span id='ZXJ9v'><b id='ZXJ9v'><form id='ZXJ9v'><ins id='ZXJ9v'></ins><ul id='ZXJ9v'></ul><sub id='ZXJ9v'></sub></form><legend id='ZXJ9v'></legend><bdo id='ZXJ9v'><pre id='ZXJ9v'><center id='ZXJ9v'></center></pre></bdo></b><th id='ZXJ9v'></th></span></q></dt></tr></i><div id='ZXJ9v'><tfoot id='ZXJ9v'></tfoot><dl id='ZXJ9v'><fieldset id='ZXJ9v'></fieldset></dl></div>
                2. 本文介绍了如何在 Oracle SQL 中选择特定字符的子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一个表格列,其结果如下:

                  Say I have a table column that has results like:

                  ABC_blahblahblah
                  DEFGH_moreblahblahblah
                  IJKLMNOP_moremoremoremore
                  

                  我希望能够编写一个查询,从所述表中选择这一列,但只返回下划线 (_) 字符之前的子字符串.例如:

                  I would like to be able to write a query that selects this column from said table, but only returns the substring up to the Underscore (_) character. For example:

                  ABC
                  DEFGH
                  IJKLMNOP
                  

                  SUBSTRING 函数似乎不能胜任这项任务,因为它是基于位置的,并且下划线的位置各不相同.

                  The SUBSTRING function doesn't seem to be up to the task because it is position-based and the position of the underscore varies.

                  我想到了 TRIM 函数(特别是 RTRIM 函数):

                  I thought about the TRIM function (the RTRIM function specifically):

                  SELECT RTRIM('listofchars' FROM somecolumn) 
                  FROM sometable
                  

                  但我不确定如何让它工作,因为它似乎只删除了某个列表/字符集,而我实际上只是在字符引导到下划线字符之后.

                  But I'm not sure how I'd get this to work since it only seems to remove a certain list/set of characters and I'm really only after the characters leading up to the Underscore character.

                  推荐答案

                  结合使用 SUBSTR、INSTR 和 NVL(对于没有下划线的字符串)将返回您想要的:

                  Using a combination of SUBSTR, INSTR, and NVL (for strings without an underscore) will return what you want:

                  SELECT NVL(SUBSTR('ABC_blah', 0, INSTR('ABC_blah', '_')-1), 'ABC_blah') AS output
                    FROM DUAL
                  

                  结果:

                  output
                  ------
                  ABC
                  

                  使用:

                  SELECT NVL(SUBSTR(t.column, 0, INSTR(t.column, '_')-1), t.column) AS output
                    FROM YOUR_TABLE t
                  

                  参考:

                  • SUBSTR
                  • INSTR
                  • 如果使用 Oracle10g+,您可以通过 REGEXP_SUBSTR 使用正则表达式.

                    If using Oracle10g+, you can use regex via REGEXP_SUBSTR.

                    这篇关于如何在 Oracle SQL 中选择特定字符的子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:“AS"和“AS"有什么区别?和“是"在 Oracle 存储过程中? 下一篇:Oracle 客户端 ORA-12541:TNS:无侦听器

                  相关文章

                    <i id='FqeZ6'><tr id='FqeZ6'><dt id='FqeZ6'><q id='FqeZ6'><span id='FqeZ6'><b id='FqeZ6'><form id='FqeZ6'><ins id='FqeZ6'></ins><ul id='FqeZ6'></ul><sub id='FqeZ6'></sub></form><legend id='FqeZ6'></legend><bdo id='FqeZ6'><pre id='FqeZ6'><center id='FqeZ6'></center></pre></bdo></b><th id='FqeZ6'></th></span></q></dt></tr></i><div id='FqeZ6'><tfoot id='FqeZ6'></tfoot><dl id='FqeZ6'><fieldset id='FqeZ6'></fieldset></dl></div>

                    <small id='FqeZ6'></small><noframes id='FqeZ6'>

                  1. <tfoot id='FqeZ6'></tfoot>
                      <bdo id='FqeZ6'></bdo><ul id='FqeZ6'></ul>
                    <legend id='FqeZ6'><style id='FqeZ6'><dir id='FqeZ6'><q id='FqeZ6'></q></dir></style></legend>