Home  >  Article  >  Database  >  Does MySQL preserve the environment in which stored procedures are created?

Does MySQL preserve the environment in which stored procedures are created?

WBOY
WBOYforward
2023-09-11 11:49:02711browse

MySQL 是否保留存储过程创建时的环境?

Actually, MySQL retains the environment in which the stored procedure was created. This can be understood through the following example where we use two bars to concatenate strings. This is only legal when the SQL mode is ansi. However, if we change the SQL mode to non-ansi, the process still works as if the original setting was still true.

Example

mysql> Set sql_mode = 'ansi'//
Query OK, 0 rows affected, 1 warning (0.14 sec)

mysql> Create Procedure Con_string()
    -> SELECT 'a'||'b'//
Query OK, 0 rows affected (0.12 sec)
mysql> Call Con_string ();
+----------+
| 'a'||'b' |
+----------+
| ab       |
+----------+
1 row in set (0.05 sec)

Query OK, 0 rows affected (0.05 sec)

mysql> Set sql_mode = '';
Query OK, 0 rows affected (0.00 sec)

mysql> Call Con_string();
+----------+
| 'a'||'b' |
+----------+
| ab       |
+----------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)

The above result set shows that even after changing the SQL mode to non-ansi, the procedure Con_string() still generates the same as if the SQL mode is still ansi the result of. But the new program will not accept both bars because we have changed the SQL mode to non-ansi.

mysql> create procedure Con_string1()
    -> Select 'a'||'b'//
Query OK, 0 rows affected (0.02 sec)

mysql> Call Con_string1()//
+----------+
| 'a'||'b' |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

Query OK, 0 rows affected, 2 warnings (0.00 sec)

The above is the detailed content of Does MySQL preserve the environment in which stored procedures are created?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete