当前位置:网站首页>Mysql中 begin..end使用遇到的坑
Mysql中 begin..end使用遇到的坑
2022-06-30 12:02:00 【全栈程序员站长】
今天在用 Navicat 连接 mysql查询的时候,遇到了一个问题,如下代码块中所示:
BEGIN
declare start_time datetime default '2021-05-06 00:00:00';
declare end_time datetime default '2021-05-07 00:00:00';
# 计算实体类店铺客单价
SELECT IFNULL(ROUND(
( SELECT sum( spu_amount_all ) / 100 FROM test_obp_data.data_user_order_goods WHERE pay_time BETWEEN start_time AND end_time AND shop_type != 3 and biz_type = 1 AND sub_biz_type = 101 AND delete_flag = 0)
/
( SELECT count( id ) FROM test_obp_data.data_user_order_goods WHERE pay_time BETWEEN start_time AND end_time AND shop_type != 3 and biz_type = 1 AND sub_biz_type = 101 AND delete_flag = 0),
2), 0) as money;
END
如图,下面我在mysql中执行了这段sql,本来是想要查询店铺订单的客单价的,然后在执行sql的过程中,抛了You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare start_time datetime default '2021-05-06 00:00:00'' at line 3
这个异常告诉我sql语法错误
开始我一直以为是自己在定义局部变量的时候,出了问题。
后来发现以上语句在触发器或者存储过程中是可以正确执行的。
查看相关文档和网上资料中得知:
通常begin-end用于定义一组语句块,在各大数据库中的客户端工具中可直接调用,但在mysql中不可用。
begin-end、流程控制语句、局部变量只能用于函数、存储过程内部、游标、触发器的定义内部。
如何创建存储过程,具体可以点击查看我的这篇博客哦~ 链接: https://blog.csdn.net/weixin_43865008/article/details/116451722?spm=1001.2014.3001.5501.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100676.html原文链接:https://javaforall.cn
边栏推荐
- Building a database model using power designer tools
- Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
- 海思3559万能平台搭建:获取数据帧修改后编码
- 串行通信接口8250
- Introduction to new features of ES6
- Browser plays RTSP video based on nodejs
- 药店管理系统
- Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
- Embedded SIG | 多 OS 混合部署框架
- Typescript readonlyarray (read only array type) details
猜你喜欢
How to detect 3D line spectral confocal sensors in semiconductors
Redis-缓存问题
lvgl 小部件样式篇
NoSQL - redis configuration and optimization
麒麟软件韩乃平:数字中国建设需要自己的开源根社区
A Generic Deep-Learning-Based Approach for Automated Surface Inspection-論文閱讀筆記
ZABBIX monitors the number of TCP connections
【目标跟踪】|pytracking 配置 win 编译prroi_pool.pyd
21. Notes on WPF binding
SuperMap iClient3D 11i for Cesium三维场景中图例使用说明
随机推荐
Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit
QT MSVC installation and commissioning
Remove invalid parentheses [simulate stack with array]
Vscode select multiple words
The format of RTSP address of each manufacturer is as follows:
Redis6 learning notes - Chapter 2 - Basic redis6 operations
Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
串行通信接口8250
Splitting e-commerce systems into micro services
Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)
Ensemble de cartes
Biological network analysis using deep learning
When building the second website with pagoda, the website always reports an error: no input file specified
8253计数器介绍
STM32 移植 RT-Thread 标准版的 FinSH 组件
Browser plays RTSP video based on nodejs
List collection
Redis6学习笔记-第二章-Redis6的基本操作
Object mapping - mapping Mapster
How do different types of variables compare with zero