MySQL ERROR 1406 (22001): Data too long for column

Bipin

Consider the table marks:

mysql> SELECT * FROM marks;
+--------+------------+-----------------------+
| name   | percentage | email                 |
+--------+------------+-----------------------+
| Bipin  | 84%        | [email protected]     |
| Deepak | 78%        | [email protected] |
| Rohith | 82%        | [email protected]    |
| Sujit  | 94%        | [email protected]   |
+--------+------------+-----------------------+

When I made the following query to insert values to the table, it resulted in an error:

mysql> INSERT INTO marks VALUES('&name','&percentage','&email');
ERROR 1406 (22001): Data too long for column 'percentage' at row 1 

It was done as an experiment based on info about another way to insert value using ('&') in SQL.

Can you specify what went wrong? According to the blog, simply pressing ENTER will insert values after the query.

The desired output:

Enter value for name: John
Enter value for percentage: 76%
Enter value for email: [email protected]
Barmar

In MySQL, session variables are prefixed with @, and they're not expanded inside quotes. So it should be:

mysql> SET @name = 'John', @percentage = '76%', @email = '[email protected]';
mysql> INSERT INTO marks VALUES(@name,@percentage,@email);

There's no automatic prompt for variables like in Oracle, you have to set them by hand.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

mysql.connector.errors.DataError: 1406 (22001): Data too long for column

"ERROR 1406: 1406: Data too long for column" but it shouldn't be?

Trying to print prime numbers from 1 to 1000 separated by with &. The error is "ERROR 1406 (22001) at line 28: Data too long for column 'p' at row 1"

Laravel Backpack Image Field Error: 1406 Data too long for column

MYSQL : Why a data of 10 536 bytes get error 1406 Data too long for a TEXT column max size of 65 535 bytes

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'ans' at row 1 (SQL: insert into `faqs` (`title`, `ans`, `updated_at`,

SQL Error: 1406, SQLState: 22001 with SpringBoot + mySQL

Laravel string data, right truncated: 1406 Data too long for column

Laravel: String data, right truncated: 1406 Data too long for column

mysql command line utility ERROR 1406 (22001) on national characters

Data too long for column error with national characters

How to solve django.db.utils.DataError: (1406, "Data too long for column 'product_team' at row 1")

Rails 4 Migration: Mysql2::Error: Data too long for column 'xxxx'

Liquibase inserting into BIT column, MySQL, data too long for column

Mysql Data too long

MySQL - Data Too Long?

MySQL LOAD DATA INFILE Data too long for column exception

column: line too long error

Mysql "Sending data" too long

Spring Data "Data too long for column at row"

How to display specified table column for Error Number: 22001/8152 SQL Server String or binary data would be truncated?

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'aboutMeText' at row 1

Value too long for column - error persisting LocalDate

Data too long for column when creating user

Doctrine: data too long for column (due to escaping)

How to fix data too long for column

With MySQL server 5.7.27 connecting with Client 8.0.19. Getting Data too long for column when using special characters

MySQL CSV Import Fails - "Data too long for column 'air_date' at row 1"

JPA, MySQL blob - data too long