<legend id='Yd0aO'><style id='Yd0aO'><dir id='Yd0aO'><q id='Yd0aO'></q></dir></style></legend>

      1. <i id='Yd0aO'><tr id='Yd0aO'><dt id='Yd0aO'><q id='Yd0aO'><span id='Yd0aO'><b id='Yd0aO'><form id='Yd0aO'><ins id='Yd0aO'></ins><ul id='Yd0aO'></ul><sub id='Yd0aO'></sub></form><legend id='Yd0aO'></legend><bdo id='Yd0aO'><pre id='Yd0aO'><center id='Yd0aO'></center></pre></bdo></b><th id='Yd0aO'></th></span></q></dt></tr></i><div id='Yd0aO'><tfoot id='Yd0aO'></tfoot><dl id='Yd0aO'><fieldset id='Yd0aO'></fieldset></dl></div>
      2. <small id='Yd0aO'></small><noframes id='Yd0aO'>

        <tfoot id='Yd0aO'></tfoot>
          <bdo id='Yd0aO'></bdo><ul id='Yd0aO'></ul>
      3. 在 SELECT 语句中提取分隔值右侧的字符

        Extract characters to the right of a delimited value in a SELECT statement(在 SELECT 语句中提取分隔值右侧的字符)

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

          <legend id='xykyK'><style id='xykyK'><dir id='xykyK'><q id='xykyK'></q></dir></style></legend>

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

                  <bdo id='xykyK'></bdo><ul id='xykyK'></ul>
                  <tfoot id='xykyK'></tfoot>

                • 本文介绍了在 SELECT 语句中提取分隔值右侧的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要提取连字符右侧的所有字符作为选择语句的一部分.选择中会有其他列.在下面的查询中,从第二列中选择了正确的三个字符.我如何在分隔符的右侧提取无限数量的字符——在我的例子中是一个连字符?我可以使用正确的功能吗?我需要使用其他功能吗?

                  I need to extract all the characters to the right of a hyphen as part of a select statement. There will be other columns in the select. In the below query, the right three characters are selected from the second column. How would I extract an indefinite number of characters to the right of a delimiter – in my case a hyphen? Can I use the right function? Do I need to use another function?

                  Select column1, right(column2,3) as extracted, column3
                  From myTable
                  

                  我使用的是 SQL Server 2008.

                  I am using SQL Server 2008.

                  推荐答案

                  这个问题有一个特定于数据库的答案.

                  This question has a database specific answer.

                  如果使用 SQL Server:

                  If using SQL Server:

                  SELECT column1
                       , RIGHT(column2,CHARINDEX('-',REVERSE(column2))-1) as extracted
                       , column3 
                  FROM myTable
                  

                  您可以添加 CASE 语句或使用 NULLIF() 以防连字符不总是存在:

                  You can add a CASE statement or use NULLIF() in case the hyphen isn't always present:

                  SELECT column1
                       , CASE WHEN column2 LIKE '%-%' THEN RIGHT(column2,CHARINDEX('-',REVERSE(column2))-1) 
                             END as extracted
                       , column3 
                  FROM myTable
                  

                  或者:

                  SELECT column1
                       , RIGHT(column2,NULLIF(CHARINDEX('-',REVERSE(column2)),0)-1) as extracted
                       , column3 
                  FROM myTable
                  

                  如果使用 MySQL,只需将 CHARINDEX() 更改为 LOCATE().我相信 Oracle 它是 INSTR() 并且前两个参数被切换,首先是您正在搜索的字符串,然后是您正在搜索的字符串.

                  If using MySQL just change CHARINDEX() to LOCATE(). I believe Oracle it's INSTR() and the first two parameters are switched, first it's the string you're searching in, then the string you're searching for.

                  这篇关于在 SELECT 语句中提取分隔值右侧的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  <i id='e1pD8'><tr id='e1pD8'><dt id='e1pD8'><q id='e1pD8'><span id='e1pD8'><b id='e1pD8'><form id='e1pD8'><ins id='e1pD8'></ins><ul id='e1pD8'></ul><sub id='e1pD8'></sub></form><legend id='e1pD8'></legend><bdo id='e1pD8'><pre id='e1pD8'><center id='e1pD8'></center></pre></bdo></b><th id='e1pD8'></th></span></q></dt></tr></i><div id='e1pD8'><tfoot id='e1pD8'></tfoot><dl id='e1pD8'><fieldset id='e1pD8'></fieldset></dl></div>

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

                  <legend id='e1pD8'><style id='e1pD8'><dir id='e1pD8'><q id='e1pD8'></q></dir></style></legend>

                        <tfoot id='e1pD8'></tfoot>
                          • <bdo id='e1pD8'></bdo><ul id='e1pD8'></ul>

                              <tbody id='e1pD8'></tbody>