按大写Oracle分割

时间:2016-07-28 12:14:30

标签: sql regex oracle

我正在寻找一个正则表达式或者其中的东西:

------------------------
| id  |   prop_name    |
------------------------
|  1  |  isThisAnExample |
------------------------

对此:

-----------------------------
| id  |   prop_name         |
-----------------------------
|  1  |  Is This An Example |
-----------------------------

当然,如果第一个字符是大写字母,并且其他单词以小写字母开头,那将会很酷。但只有分裂他们也没关系。

3 个答案:

答案 0 :(得分:1)

也许这是你正在寻找的正则表达式

"在每个小写字符之间插入一个空格,后跟一个大写字符":

func application(application: UIApplication,
                 openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,UIApplicationOpenURLOptionsAnnotationKey: annotation]
    return GIDSignIn.sharedInstance().handleURL(url,
                                                sourceApplication: sourceApplication,
                                                annotation: annotation)
}

第一个字符可以简单地用大写字母替换

select regexp_replace('IsThisAnExample', '([[:lower:]])([[:upper:]])', '\1 \2') from dual

因此,首先替换结果的第一个字符和regexp_replace:

select upper(substr('isThisAn Example', 1,1))||substr('isThisAn Example', 2) from dual;

如果只有句子的第一个字符应为大写字母,请尝试:

select regexp_replace(upper(substr('isThisAn Example', 1,1))||substr('isThisAn Example', 2), '([[:lower:]])([[:upper:]])', '\1 \2') from dual;

答案 1 :(得分:0)

最好使用正则表达式,但无论如何:

SELECT listagg(splitted, '') within GROUP (ORDER BY lvl) FROM( 
    SELECT LEVEL lvl, CASE WHEN SUBSTR(your_string, LEVEL, 1) = 
                    UPPER(SUBSTR(your_string, LEVEL, 1)) 
        THEN ' ' || SUBSTR(your_string, LEVEL, 1) ELSE 
                    SUBSTR(your_string, LEVEL, 1)  END splitted
FROM (SELECT 'isThisAnExample' your_string FROM dual) 
CONNECT BY LEVEL <= LENGTH(your_string) );

答案 2 :(得分:0)

与Frank的解决方案类似,但更简单(尽可能减少正则表达式的使用):

with
     input ( str ) as (
       select 'isThisAnExample' from dual
     )
select upper(substr(str, 1, 1)) ||
       lower(regexp_replace(substr(str, 2), '(^|[[:lower:]])([[:upper:]])', '\1 \2'))
          as modified_str
from   input;

MODIFIED_STR
------------------
Is this an example

1 row selected.
相关问题