开发者

MySQL Truncates 0 in VARCHAR field

开发者 https://www.devze.com 2023-01-20 07:40 出处:网络
I have a VARCHAR field in a MySQL table like so - CREATE TABLE desc( `pk` varchar(10) NOT NULL UNIQUE, ...

I have a VARCHAR field in a MySQL table like so -

CREATE TABLE desc(
    `pk` varchar(10) NOT NULL UNIQUE,
    ...
);

The value in pk field is of the type - (xx0000001, xx0000002, ...). But when I insert these into my table the values in pk field get truncated to (xx1, xx2, ...).

How to prevent this?

UPDATE: Adding the INSERTstatement

INSERT INTO desc 开发者_如何学编程(pk) VALUES ("xx0000001");


It could be that the viewer you are using to LOOK at the values is displaying the info incorrectly because it is trying to interpret that string as a number, or that mysql may be interpreting your numbers as hexadecimal or something strange.

What happens if you do

INSERT INTO desc (pk) VALUES ("xx0000099"); 

Does it come back as xx99? or some other value?


Looks like you are referencing different tables in your two statements, text and desc?


Possibly somewhere along your program logic the value is interpreted as a hexadecimal or octal number?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号