当前位置:网站首页>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
边栏推荐
- Flutter 从零开始 007 输入框
- A High-Precision Positioning Approach for Catenary Support Components With Multiscale Difference阅读笔记
- Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
- Use of redis in projects
- Two batches of pure milk are unqualified? Michael responded that he was conducting a large-scale screening and sampling inspection of products
- SuperMap iClient3D for WebGL 加载TMS瓦片
- 各厂家rtsp地址格式如下:
- Conference Preview - Huawei 2012 lab global software technology summit - European session
- DMA控制器8237A
- [leetcode] 15. Sum of three numbers
猜你喜欢

Understanding and learning of MySQL indexing and optimization

Yolov5 export the pit encountered by onnx

腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
![[cloud native | kubernetes] in depth understanding of deployment (VIII)](/img/88/4eddb8e6535a12541867b027b109a1.png)
[cloud native | kubernetes] in depth understanding of deployment (VIII)

90. (cesium chapter) cesium high level listening events

NoSQL - redis configuration and optimization

A high precision positioning approach for category support components with multiscale difference reading notes

Set集合

Four Misunderstandings of Internet Marketing

MySQL built-in functions
随机推荐
Serial communication interface 8250
Yolov5 export the pit encountered by onnx
海思3559万能平台搭建:YUV格式简介
SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询
A high precision positioning approach for category support components with multiscale difference reading notes
[cf] 803 div2 B. Rising Sand
90.(cesium篇)cesium高度监听事件
QT MSVC installation and commissioning
Hannaiping of Qilin software: the construction of Digital China needs its own open source root community
Swagger2 automatically generates API documents
MySQL索引和优化的理解学习
R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates a dynamic scatter graph animation (GIF), and uses the labs function to add a dynamic time title to
21. Notes on WPF binding
用于生成学习任务的量子神经网络2022最新综述
[leetcode] 15. Sum of three numbers
[cf] 803 div2 B. Rising Sand
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
不同类型的变量与零究竟是如何比较
Redis6学习笔记-第二章-Redis6的基本操作
After the node is installed in the NVM, the display is not internal or external when the NPM instruction is used