简体   繁体   中英

Replace string from column with NULL in sql

I have a df:

Col1   col2 
1222    abc
---    bbb
111  nmnm

Whenever I detect --- in Col1 I want to convert that to NULL, how to do that?

Tried so far:

 select replace(Col1, '---', NULL) from df

But even after this the original table is unchanged

You need to update the table:

UPDATE df
SET Col1 = NULL
WHERE Col1 = '---';

As for ad-hoc query:

select replace(Col1, '---', NULL) from df
<->
select nullif(col1, '---') AS col1 from df;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM