2022-07-25 553
mysql存储过程怎样变量赋值
MySQL变量赋值就一个坑。这个坑有两种填法。
第一种是众所周知的:set 变量名=值/赋值语句
第二种是:select … into 变量名 …; 或者 select … into 变量名;
第一种,我在网上看很多人说变量名前面要加@符合,但是实际上是不必要的,只有一些特殊情况是必须要@符合,大部分时候不加也不影响存储过程的使用的。
例如:
set g_grant_ex='gamedb.tb_exchange_'; set @g_grant_ex='gamedb.tb_exchange_'; /*这其实是一样的效果*/
第二种,这个就更坑了。我之前看别人用的是云里雾里。后来动手试了几次才发现。。。。。。。蛮好用的~
例如:
1.select count(*) into g_err from information_schema.TABLES t where t.TABLE_SCHEMA='gamedb' and t.TABLE_NAME=concat('tb_recharge_',g_year); 2.select count(*) from information_schema.TABLES t where t.TABLE_SCHEMA='gamedb' and t.TABLE_NAME=concat('tb_recharge_',g_year) into g_err; /*这两个效果也是一样的*/
原文链接:https://77isp.com/post/2247.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态