【问题标题】:oracle regexp_substr to fetch stringoracle regexp_substr 获取字符串
【发布时间】:2014-08-18 05:45:11
【问题描述】:

我有一个类似的 sql 查询

从emp中选择count(distinct empno),count(distinct(deptno empname empid))

我想获取第一次出现的计数及其内容,例如:

count(distinct empno)

我尝试了下面的sql语句,但它不起作用,

SQL >select regexp_substr('select count(distinct empno), count(distinct(deptno)) from emp', 'count *( distinct .)') 从双;

REGEXP_SUBSTR('SELECTCOUNT(DISTINCTEMPNO),COUN ---------------------------------- 计数(不同的empno ), count(distinct(deptno ))

我希望输出返回如下:

REGEXP_SUBSTR('SELECTCOUNT(DISTINCTEMPNO)

count(distinct empno),

正则表达式不应该匹配第二个)右括号,它应该匹配第一个右括号。

【问题讨论】:

标签: sql regex oracle plsql


【解决方案1】:

您的正则表达式中的* 吃了一切,您需要使正则表达式引擎匹配最短的可能性。

count *\([^\)]\)(?=,)

【讨论】:

    猜你喜欢
    • 2012-06-26
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多