包含两个 VARCHAR2 值时如何忽略空格
How to ignore spaces when comprising two VARCHAR2 values
我遇到了比较问题,
我不知道如何强制 oracle 忽略空格
我已经尝试 trim 函数和替换(列,' ',''),但仍然
即使我尝试对两列都使用 to_char
这是查询
select
replace(nvl(MEMBER_CARD_NO,'x'),' ','') x,
replace(nvl(COL_CRD_ID,'x'),' ','') y,
case when
replace(nvl(MEMBER_CARD_NO,'x'),' ','') =
replace(nvl(COL_CRD_ID,'x'),' ','') then 'y' else 'no'end z
from tb_sales
where
case when
replace(nvl(MEMBER_CARD_NO,'x'),' ','') =
replace(nvl(COL_CRD_ID,'x'),' ','') then 'y' else 'no'end ='no'
每列的数据类型如下所述
MEMBER_CARD_NO : VARCHAR2(30 字节)
COL_CRD_ID:VARCHAR2(30 字节)
下面是一条记录的示例
x |y |z
17140974|"17140974 " |no
第二个复制的时候显示双引号
您有双引号 和 空格,因此您需要将两者都删除。 translate()
方便:
where x = translate(y, 'a "', 'a')
Here 是一个 db<>fiddle.
这听起来像是在使用 varchar2 时对 ASCII 和 Unicode 的问题裁判,它需要在像这样替换之前使用 char 'N'
select
replace(nvl(MEMBER_CARD_NO,'x'), '\W','') x,
replace(nvl(COL_CRD_ID,'x'),'\W','') y,
case when
replace(nvl(MEMBER_CARD_NO,'x'),'\W','') =
replace(nvl(COL_CRD_ID,'x'),'\W','') then 'y' else 'no'end z
from tb_sales
where
case when
replace(nvl(MEMBER_CARD_NO,'x'),'\W','') =
replace(nvl(COL_CRD_ID,'x'),'\W','') then 'y' else 'no'end ='no'
如果不起作用,请使用 regexp_replace(coulmn, '[[:space:]]*','')
而不是 replace(coulmn, ' ','')
我遇到了比较问题, 我不知道如何强制 oracle 忽略空格
我已经尝试 trim 函数和替换(列,' ',''),但仍然
即使我尝试对两列都使用 to_char
这是查询
select
replace(nvl(MEMBER_CARD_NO,'x'),' ','') x,
replace(nvl(COL_CRD_ID,'x'),' ','') y,
case when
replace(nvl(MEMBER_CARD_NO,'x'),' ','') =
replace(nvl(COL_CRD_ID,'x'),' ','') then 'y' else 'no'end z
from tb_sales
where
case when
replace(nvl(MEMBER_CARD_NO,'x'),' ','') =
replace(nvl(COL_CRD_ID,'x'),' ','') then 'y' else 'no'end ='no'
每列的数据类型如下所述
MEMBER_CARD_NO : VARCHAR2(30 字节)
COL_CRD_ID:VARCHAR2(30 字节)
下面是一条记录的示例
x |y |z
17140974|"17140974 " |no
第二个复制的时候显示双引号
您有双引号 和 空格,因此您需要将两者都删除。 translate()
方便:
where x = translate(y, 'a "', 'a')
Here 是一个 db<>fiddle.
这听起来像是在使用 varchar2 时对 ASCII 和 Unicode 的问题裁判,它需要在像这样替换之前使用 char 'N'
select
replace(nvl(MEMBER_CARD_NO,'x'), '\W','') x,
replace(nvl(COL_CRD_ID,'x'),'\W','') y,
case when
replace(nvl(MEMBER_CARD_NO,'x'),'\W','') =
replace(nvl(COL_CRD_ID,'x'),'\W','') then 'y' else 'no'end z
from tb_sales
where
case when
replace(nvl(MEMBER_CARD_NO,'x'),'\W','') =
replace(nvl(COL_CRD_ID,'x'),'\W','') then 'y' else 'no'end ='no'
如果不起作用,请使用 regexp_replace(coulmn, '[[:space:]]*','')
而不是 replace(coulmn, ' ','')