【问题标题】:Regex for string not ending with given suffix in teradata query正则表达式在 teradata 查询中不以给定后缀结尾的字符串
【发布时间】:2019-04-10 19:30:36
【问题描述】:

我正在尝试从数据库中获取以引号开头且不以引号结尾的行。我在名称列中有如下行,

"TEXT
"TEXT"
"TEST
"TEST"

选择查询的期望输出,

"TEXT
"TEST

SQL 查询,

SELECT * FROM db.supplier where  regexp_instr(Name_ ,'^[\"][\w-_.]+(?<!")') = 1;

我知道正则表达式应该以 $ 结尾来标记结尾,但它也没有用。任何建议都非常感谢。

【问题讨论】:

    标签: sql teradata teradata-sql-assistant


    【解决方案1】:

    like怎么样?

    where Name_ like '"%' and Name_ not like '%"'
    

    这看起来很简单。你也可以使用regexp_similar():

    where regexp_similar(Name_, '^".*[^"]$')
    

    【讨论】:

      【解决方案2】:

      为什么要使用否定的lookbehind?这将返回任何以双引号开头但不以双引号结尾的值:

      where regexp_similar(Name_ ,'".+[^"]') = 1
      

      【讨论】:

        猜你喜欢
        • 2022-01-09
        • 2019-02-21
        • 1970-01-01
        相关资源
        最近更新 更多