Python Microsoft SQL 中的错误“字符串或二进制数据将被截断”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39200572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error 'String or binary data would be truncated' in Microsoft SQL
提问by Aminah Nuraini
I got this error when inserting data to Microsoft SQL.
将数据插入 Microsoft SQL 时出现此错误。
error: ('22001', '[22001] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]String or binary data would be truncated. (8152) (SQLParamData); [01000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]The statement has been terminated. (3621)')
错误: ('22001', '[22001] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server] 字符串或二进制数据将被截断。(8152) (SQLParamData); [01000] [Microsoft][ODBC 驱动程序13 for SQL Server][SQL Server]语句已终止。(3621)')
FYI, I use Python 2.7 and pyodbc
library.
仅供参考,我使用 Python 2.7 和pyodbc
库。
What is that error about? What should I do to solve it?
这个错误是关于什么的?我应该怎么做才能解决它?
回答by Aminah Nuraini
Based on this link: http://www.sql-server-performance.com/2007/string-or-binary-data-truncated/
基于此链接:http: //www.sql-server-performance.com/2007/string-or-binary-data-truncated/
This error message appears when you try to insert a string with more characters than the column can maximal accommodate.
当您尝试插入一个字符串的字符数超过该列可容纳的最大字符数时,会出现此错误消息。
回答by Unnikrishnan R
figure out the issue using following step. in your insert satement ,use 'LEN' function to find the length of the input columns.
使用以下步骤找出问题。在您的插入语句中,使用“LEN”函数来查找输入列的长度。
suppose you are selecting data from a temp table for input. use the below query to find out maximum size of that column and compare with the actual size of the column in your original table (table you are going to insert data).
假设您正在从临时表中选择数据进行输入。使用以下查询找出该列的最大大小,并与原始表(要插入数据的表)中该列的实际大小进行比较。
SELECT MAX(LEN(column1))
FROM #yourInputData