<bdo id='yQo0t'></bdo><ul id='yQo0t'></ul>

  1. <small id='yQo0t'></small><noframes id='yQo0t'>

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

      使用 SQL 逐字反转字符串

      Reverse String Word by Word using SQL(使用 SQL 逐字反转字符串)

      <small id='9SeKr'></small><noframes id='9SeKr'>

      <tfoot id='9SeKr'></tfoot>
              <tbody id='9SeKr'></tbody>

            1. <legend id='9SeKr'><style id='9SeKr'><dir id='9SeKr'><q id='9SeKr'></q></dir></style></legend>
            2. <i id='9SeKr'><tr id='9SeKr'><dt id='9SeKr'><q id='9SeKr'><span id='9SeKr'><b id='9SeKr'><form id='9SeKr'><ins id='9SeKr'></ins><ul id='9SeKr'></ul><sub id='9SeKr'></sub></form><legend id='9SeKr'></legend><bdo id='9SeKr'><pre id='9SeKr'><center id='9SeKr'></center></pre></bdo></b><th id='9SeKr'></th></span></q></dt></tr></i><div id='9SeKr'><tfoot id='9SeKr'></tfoot><dl id='9SeKr'><fieldset id='9SeKr'></fieldset></dl></div>
                <bdo id='9SeKr'></bdo><ul id='9SeKr'></ul>
              • 本文介绍了使用 SQL 逐字反转字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要反转句子或字符串中的单词位置.

                I would need to reverse the word positions in a sentence or String.

                For example : "Hello World! I Love StackOverflow", to be displayed as "StackOverflow Love I World! Hello". 
                

                可以用 SQL 来完成吗?字长不大于 VARCHAR2(4000),这是 Oracle VARCHAR2 表列中支持的最大长度.

                Can it be done with a SQL ? The word length is no greater than VARCHAR2(4000) which is the maximum length support in a Oracle VARCHAR2 table column.

                我只得到了反转字符串(逆序字符)的解决方案

                I got solutions for reversing a string (Characters in reverse order) only

                推荐答案

                创建函数:

                REGEXP_SUBSTR('Your text here','[^ ]+', 1, ?) 将使用空格作为分隔符从文本中提取一个单词.Tt 在异常时返回原始字符串本身!

                REGEXP_SUBSTR('Your text here','[^ ]+', 1, ?) will extract a word from the text using Space as a delimiter. Tt returns the original String itself on Exception!

                CREATE OR REPLACE FUNCTION reverse_words (v_STRING IN VARCHAR2)
                RETURN VARCHAR2
                IS
                   L_TEMP_TEXT  VARCHAR2(4000);
                   L_FINAL_TEXT  VARCHAR2(4000);
                   V_LOOPCOUNT NUMBER :=0;
                   T_WORD VARCHAR2(4000);
                BEGIN
                      L_TEMP_TEXT := regexp_replace(V_STRING,'[[:space:]]+',' '); -- Replace multiple spaces as single
                      LOOP
                        v_LOOPCOUNT := v_LOOPCOUNT+1;
                        T_WORD      := REGEXP_SUBSTR(L_TEMP_TEXT,'[^ ]+', 1, V_LOOPCOUNT);
                        L_final_TEXT := T_WORD||' '||L_final_TEXT;
                      EXIT WHEN T_WORD IS NULL;
                      END LOOP;
                   RETURN(TRIM(L_final_TEXT));
                EXCEPTION
                    WHEN OTHERS THEN
                        DBMS_OUTPUT.PUT_LINE(sqlerrm||chr(10)||dbms_utility.format_error_backtrace);
                        RETURN V_STRING;
                END reverse_words;
                /
                

                示例结果:

                您可以从 your_table 中调用 reverse_words(yourcolumn)

                You can call reverse_words(yourcolumn) from your_table

                SQL> select reverse_words('Hello World! I Love StackOverflow') "Reversed" from dual;
                
                Reversed
                --------------------------------------------------------------------------------
                StackOverflow Love I World! Hello
                

                这篇关于使用 SQL 逐字反转字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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='YgzQ8'><tr id='YgzQ8'><dt id='YgzQ8'><q id='YgzQ8'><span id='YgzQ8'><b id='YgzQ8'><form id='YgzQ8'><ins id='YgzQ8'></ins><ul id='YgzQ8'></ul><sub id='YgzQ8'></sub></form><legend id='YgzQ8'></legend><bdo id='YgzQ8'><pre id='YgzQ8'><center id='YgzQ8'></center></pre></bdo></b><th id='YgzQ8'></th></span></q></dt></tr></i><div id='YgzQ8'><tfoot id='YgzQ8'></tfoot><dl id='YgzQ8'><fieldset id='YgzQ8'></fieldset></dl></div>

                  <bdo id='YgzQ8'></bdo><ul id='YgzQ8'></ul>

                    • <small id='YgzQ8'></small><noframes id='YgzQ8'>

                      1. <legend id='YgzQ8'><style id='YgzQ8'><dir id='YgzQ8'><q id='YgzQ8'></q></dir></style></legend>
                          <tbody id='YgzQ8'></tbody>

                          <tfoot id='YgzQ8'></tfoot>