Get the App
SLTechnology News&Howtos  ›  Database  › 

How to deal with the sql_mode problem in MySQL stored procedure

Shulou Source: shulou.com Published: 2022-05-31 15:29:33 09月17日 Update

This article mainly introduces how to deal with the sql_mode problem in MySQL stored procedures, which is very detailed and has a certain reference value. Friends who are interested must read it!

Sql_mode='STRICT_TRANS_TABLES' is set in my.cnf

However, it is found that illegal data is still written. For example, the original value of the unsigned integer field is 0 and can be subtracted. Of course, the result is overflowed. After checking, it is found that the default sql_mode in the stored procedure does not use global's sql_mode. The test is as follows:

CREATE PROCEDURE p_test ()

BEGIN

Select @ @ session.sql_mode,@@global.sql_mode

END

Call p_test ()

+-+ +

| | @ @ session.sql_mode | @ @ global.sql_mode |

+-+ +

| | STRICT_TRANS_TABLES |

+-+ +

1 row in set (0.00 sec)

CREATE PROCEDURE p_test1 ()

BEGIN

Set sql_mode=@@global.sql_mode

Select @ @ session.sql_mode,@@global.sql_mode

END

Call p_test1 ()

+-+ +

| | @ @ session.sql_mode | @ @ global.sql_mode |

+-+ +

| | STRICT_TRANS_TABLES | STRICT_TRANS_TABLES |

+-+ +

1 row in set (0.00 sec)

These are all the contents of the article "how to deal with sql_mode problems in MySQL stored procedures". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Procedures storage problems processing content articles values interests fields guys partners data integers more knowledge symbols results industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Linux Redmi OPPO Reno