Mysql-用户变量的声明与使用

#声明变量

#1.标识符不能以数字开头

#2.只能使用_或$符号,不能使用其他符号

#3.不能使用系统关键字

sql 复制代码
set@userName='刘德华';
select @userName:='刘青云';#将赋值与查询结合

#查询变量、使用变量,匿名的时候建议加上as

select @userName as '读取到的userName变量值';

#整数类型与浮点数类型测试

sql 复制代码
set @x=5,@y=7;
select @x+@y as '5+7的结果';
set @dx=0.5,@dy=2;
select @dx+@dy;#浮点数计算异常显示无限000

#去零操作 重新赋值既可以做到

sql 复制代码
set @result=(select @dx+@dy);
select @result;

#通过修改变量的方式进行精准查询

sql 复制代码
set @cityName1='Kabul';
set @cityName2='Qandahar';
set @cityName3='Maastricht';
select * from city where`Name`=@cityName1;

select * from city where `Name` in (@cityName1,@cityName2,@cityName3);
select @cityName;

相关推荐
五岳7 小时前
分库分表数据源ShardingSphereDataSource的Connection元数据误用问题分析
java·mysql·爬坑
悄悄敲敲敲8 小时前
MySQL表的约束
数据库·mysql
鼠爷ねずみ8 小时前
SpringCloud前后端整体开发流程-以及技术总结文章实时更新中
java·数据库·后端·spring·spring cloud
九皇叔叔8 小时前
MySQL 数据库 Read View 详解
数据库·mysql·mvcc·read view
Elastic 中国社区官方博客9 小时前
Elasticsearch:圣诞晚餐 BBQ - 图像识别
大数据·数据库·elasticsearch·搜索引擎·ai·全文检索
cui_win10 小时前
Prometheus实战教程 - Redis 监控
数据库·redis·prometheus
JIngJaneIL10 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
TG:@yunlaoda360 云老大10 小时前
华为云国际站代理商备份策略设置过程中遇到问题如何解决?
服务器·数据库·华为云
SelectDB11 小时前
Doris Catalog 已上线!性能提升 200x,全面优于 JDBC Catalog,跨集群查询迈入高性能分析时代
数据库·数据分析·apache
TAEHENGV11 小时前
进度跟踪模块 Cordova 与 OpenHarmony 混合开发实战
android·javascript·数据库