Does MySQL preserve the environment at the time the stored procedure created?


Actually, MySQL preserves the environment at the time the stored procedure is created. It can be understood with the help of following the example in which we are using two bars for concatenating strings. This is only legal while SQL mode is ansi. But if we change the SQL mode to non-ansi, the procedure still works as if the original setting is 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 still the procedure Con_string() is producing the same result as if the SQL mode is still ansi. But the new procedure will not accept two 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)

Updated on: 22-Jun-2020

37 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements