我们可以在 mysql varchar 列中存储负号 (-) 和加号 (+) 号吗 [英] can we store negative (-) and plus (+) sign numbers in mysql varchar column

查看:84
本文介绍了我们可以在 mysql varchar 列中存储负号 (-) 和加号 (+) 号吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 mysql 的 varchar 列中存储带有加号或减号的数字.我正在使用 php.

I need to store numbers with plus or minus signs in a varchar column in mysql. I am using php.

+100 节省 100

+100 saves 100

100+ 插入失败

-100 正常显示-100

-100 its ok shows -100

100- 插入失败

推荐答案

根据您指定的情况,很可能您没有在值中添加引号,MySQL 将这些值视为整数,然后将它们转换为 VARCHAR(在您的第一种和第三种情况).请检查您的 INSERT 语句并将引号添加到值:

According to the cases you specified, most probably you have not added the quotes to the values and MySQL treats the values as integers and then converts them to VARCHAR (in your first and third cases). Please check your INSERT-statement and add the quotes to value:

$query = "INSERT INTO table (field) VALUES ('$value')";

当然最好使用数字数据类型来存储这些值.

And of course it is better to use numeric datatypes for storing such values.

这篇关于我们可以在 mysql varchar 列中存储负号 (-) 和加号 (+) 号吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆