gpt4 book ai didi

sql-server-2008 - 为什么在 SQL 中插入 *

转载 作者:行者123 更新时间:2023-12-04 07:15:48 25 4
gpt4 key购买 nike

这发生在我刚刚测试的时候。我创建了一个表作为

    Create Table Test_Table
(
Field_char char(1)
);

当我想用代码插入值时

Insert Into Test_Table(Field_char)
Select 13;

它在列中插入“*”。对于单个数字,它按原样插入它们。如果长度从 1 修改为 2,对于 3 位输入(例如 100 等)也会发生类似的事情。

这是为什么?

最佳答案

在您的创建语句中,您将 Field_char 的长度设置为 1 (char(1))。这意味着您的条目的长度必须小于或等于 1。有效条目为 1,2 等。无效条目为 12、13,因为它们长于 1 个字符 -> * 是表示无效值的占位符。

编辑:(感谢 Vladimir)

更准确的看一看here .

Truncating and Rounding Results

[...] Conversions to char, varchar, nchar, nvarchar, binary, and varbinary are truncated, except for the conversions shown in the following table.

我们有以下条目:

From data type int to data type char result *

其中 * = 结果长度太短无法显示

关于sql-server-2008 - 为什么在 SQL 中插入 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30075781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com