如果列包含 sql 中的字母数字字符,如何将列设置为空白

How to set column blank if column contains alphanumeric characters in sql

我必须从 table 中获取 MSISDN 的 1 列。

结果如图所示,

enter image description here

在某些行中它 returns string like nt>'1 每次都不一样。

如果发生这种情况,我想将列设置为空白而不删除行。

select case
         when REGEXP_LIKE(MSISDN, '[A-Za-z]') then null
         else MSISDN
       end as MSISDN
from MyTable

您可以在 SQL

中使用 CASE 语句解决此问题
SELECT CASE WHEN MSISDN = 'nt>1' THEN '' ELSE MSISDN END AS MSISDN

使用 REPLACE String 函数替换您的特定字符串:

  SELECT REPLACE(Your_columnName,'nt&''gt;1','')
  FROM Your_table 

您可以比较字符串或使用 LIKE 运算符。一些选项是:

SELECT CASE
         WHEN MSISDN = 'nt>1'            THEN NULL -- match nt&gt1;
         WHEN MSISDN LIKE '%>%'          THEN NULL -- match > anywhere in the string
         WHEN LOWER( MSISDN ) LIKE '%<%' THEN NULL -- match < ignoring case
         WHEN MSISDN LIKE '%&%;%'           THEN NULL -- match & followed later by ;
         ELSE MSISDN
       END AS parsed_msisdn
FROM   your_table