MySQL 在 SELECT 上用逗号替换点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24056252/
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-08-31 20:36:59  来源:igfitidea点击:

Replace dot with comma on SELECT

mysql

提问by user1876234

I would like to replace any 'dot' character in my query string, on SELECTing fields from database.

我想在SELECT数据库中的 ing 字段上替换查询字符串中的任何“点”字符。

I'll need to modify lots of queries, I'm willing there's a function that will work to all columns on SELECT. I mean something like this SELECT DOT_TO_COMMA(*) FROM...

我需要修改很多查询,我愿意有一个函数可以对SELECT. 我的意思是这样的SELECT DOT_TO_COMMA(*) FROM...

Right now what I have:

现在我所拥有的:

SELECT price, lastprice FROM products

SELECT price, lastprice FROM products

OUTPUT: 22.10, 5.24

OUTPUT: 22.10, 5.24

EXPECTATION: 22,10, 5,25

EXPECTATION: 22,10, 5,25

回答by fancyPants

SELECT REPLACE(price, '.', ',') AS price
FROM products;
  • read more about it here

You have to wrap each column you need to replace with the function. Using replace(*)is not possible.

您必须用函数包装需要替换的每一列。使用replace(*)是不可能的。

回答by Ajs Rock

please try this...

请试试这个...

this is working

这是工作

SELECT REPLACE(price,'.',',') AS price, REPLACE(lastprice,'.',',') AS lastprice FROM products

回答by rickslayer

In my case replace doesn't work well with negative numbers.

在我的情况下,替换对负数不起作用。

I use SELECT FORMAT (price,0). Second parameter is de decimal numbers

我用SELECT FORMAT (price,0). 第二个参数是十进制数

checkout http://www.mysqltutorial.org/mysql-format-function/

结帐http://www.mysqltutorial.org/mysql-format-function/