将 null 插入 char(1)
我正在创建一个 INSERT 脚本,但遇到了一个问题。有一个中间初始字段是 char(1)
有时记录在该字段中没有任何内容,所以我输入 NULL。这会导致数据列错误过长。我不想只输入“”,因为这样只会留下一个空格。
还有其他办法解决这个问题吗?
I am creating a INSERT script and I am coming across a problem. There is a middle initial field that is a char(1)
Sometimes the records don't have anything in that field so I put a NULL. This causes a Data too long for column error. I don't want to just put ' ' as that leaves just a blanks space.
Is there another way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您可能正在尝试将字符串
'NULL'
插入char(1)
字段,而不是 SQL NULL,并且您启用了严格的 SQL 模式,这可以防止它被截断为N
。如果可以,请
在 MySQL shell 中运行以确定目标字段是否接受 NULL。在没有上下文的情况下(您是将其作为纯 SQL 运行,还是从另一种语言的某个客户端程序连接到数据库?),很难提供准确的解决方案,但您可能会遇到这样的情况:
其中 'NULL' 只是一个字符串没有特殊意义,当你想要的是
下面是一个例子:
有点下注 - 抱歉,如果没有用......
It sounds like you may be attempting to insert the string
'NULL'
into thechar(1)
field, rather than an SQL NULL, and you have strict SQL mode enabled, which prevents this being truncated toN
.If you are able, run
in the MySQL shell to determine whether your target field accepts NULLs. With no context (are you running this as pure SQL, or connecting to the database from some client program in another langauge?) it's difficult to provide the exact solution, but you may have something like this:
where 'NULL' is simply a string with no special meaning, when what you intend is
Here's an illustration:
Bit of a punt - apologies if no use ...