The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed unless the PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled.
如何在 Connector/Net 中启用 PAD_CHAR_TO_FULL_LENGTH 标志? (不是 ODBC)
最佳答案
如 Server SQL Modes 下所述:
To change the SQL mode at runtime, set the global or session
sql_mode
system variable using aSET
statement:SET GLOBAL sql_mode = '<strong><em>modes</em></strong>'; SET SESSION sql_mode = '<strong><em>modes</em></strong>';
Setting the
GLOBAL
variable requires theSUPER
privilege and affects the operation of all clients that connect from that time on. Setting theSESSION
variable affects only the current client. Each client can change its sessionsql_mode
value at any time.
因此您想要按照以下几行执行一个普通的旧 SQL 命令:
SET SESSION sql_mode = 'PAD_CHAR_TO_FULL_LENGTH';
关于c# - 在 MySql Connector/Net 上设置 PAD_CHAR_TO_FULL_LENGTH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33583181/