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

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

WBOY
Release: 2023-09-11 11:49:02
forward
761 people have browsed it

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template