是否有一个Oracle Trim等效项适用于完全由空格组成的VARCHAR字段


SELECT 1 FROM dual where trim('X ') = 'X'

给出 1.

SELECT 1 FROM dual where trim(' ') = ''

不提供行。

有没有一种简单的方法可以选择field正则表达式缺少空格的所有行?

有没有办法"欺骗"修剪' '并给予''

在 Oracle 中,空字符串为 NULL。 所以传统的方法将是这样的

SELECT 1 
  FROM dual 
 WHERE trim(' ') IS NULL

当然,这也将返回NULL列的结果。 如果您想要列非 NULL 且仅由空格组成的情况

SQL> ed
Wrote file afiedt.buf
  1  with t as (
  2    select 1 id, ' ' str from dual union all
  3    select 2, null from dual union all
  4    select 3, 'a' from dual
  5  )
  6  select *
  7    from t
  8   where trim(str) is null
  9*    and str is not null
SQL> /
        ID S
---------- -
         1

只是为了完善答案,如果您也想使用一个简单的regexp_like

SQL> ed
Wrote file afiedt.buf
  1  with t as (
  2    select 1 id, ' ' str from dual union all
  3    select 2, null from dual union all
  4    select 3, 'a ' from dual
  5  )
  6  select *
  7    from t
  8*  where regexp_like( str, '^[[:space:]]+$' )
SQL> /
        ID ST
---------- --
         1

最新更新