oracle 如何用空格替换所有返回的零

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5498655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:12:08  来源:igfitidea点击:

How can I replace all zeroes returned with blank space

sqloracle

提问by code511788465541441

How can I remove all zeros returnd from an sql query

如何删除从 sql 查询返回的所有零

edit: My table has a lot of cells that contain 0. i want all zeros to be replaced by a blank space

编辑:我的表格有很多包含 0 的单元格。我希望所有的零都被一个空格替换

for example:

例如:

location |count

位置 |计数

location1 | 0

位置1 | 0

localtion2| 2

位置2| 2

turned into

转换成

location |count

位置 |计数

location1 |

位置1 |

localtion2| 2

位置2| 2

回答by Jacob Ewald

The function is oddly enough named REPLACE. Check Oracle's documentation here: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions134.htm

奇怪的是,该函数名为 REPLACE。在此处查看 Oracle 的文档:http: //download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions134.htm

SELECT REPLACE(COLUMN_NAME,'0',' ') "Column Name" FROM YOUR_TABLE_NAME;

SELECT REPLACE(COLUMN_NAME,'0',' ') "Column Name" FROM YOUR_TABLE_NAME;

回答by tbone

I assume you mean leading zeros? Try ltrim:

我假设你的意思是前导零?尝试 ltrim:

select ltrim('00001234', '0') from dual;

回答by kevin cline

SELECT DECODE(n, 0, ' ', n) ...

回答by Mark Mooibroek

Use the case statement maybe ?

也许使用 case 语句?

SELECT 
    CASE 
        WHEN numbers = 0 THEN "Zero" 
        WHEN numbers = -1 THEN "Under zero"
        ELSE "Not Empty" 
    END
FROM t_able