create procedure stc_info(in Tid char(8), in type int, out info varchar(10)) BEGIN IF type = 1 then set info = CAST((select count(Tno) from stc where Tno=Tid group by Tno) AS CHAR); ELSEIF type = 2 then set info = CAST((select AVG(Score) from stc where Tno=Tid group by Tno) AS CHAR); ELSE set INFO = 'error!!!'; end if; END;语句错误 提示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 '' at line 7

时间: 2024-02-10 18:07:45 浏览: 19
这个错误可能是因为存储过程中的语句没有以分号结尾。请尝试将代码修改如下: ``` create procedure stc_info(in Tid char(8), in type int, out info varchar(10)) BEGIN IF type = 1 then set info = CAST((select count(Tno) from stc where Tno=Tid group by Tno) AS CHAR); ELSEIF type = 2 then set info = CAST((select AVG(Score) from stc where Tno=Tid group by Tno) AS CHAR); ELSE set INFO = 'error!!!'; end if; END; ``` 在存储过程中,应该使用 BEGIN 和 END 来标记代码块的开始和结束。此外,SQL 语句应该以分号结尾。在这个存储过程中,每个 SQL 语句都已经以分号结尾,但是在最后的 END 后面也要加上分号,以表示存储过程的结束。
相关问题

create procedure stc_info(in Tid char(8), in type int, out info varchar(10)) IF type = 1 then set info = CAST((select count(Tno) from stc where Tno=Tid group by Tno) AS CHAR); ELSEIF type = 2 then set info = CAST((select AVG(Score) from stc where Tno=Tid group by Tno) AS CHAR); ELSE set type = 'error!!!'; end if;为什么错误

这个错误可能是因为在 IF 语句中缺少了 BEGIN 和 END 标记,应该将代码修改如下: ``` create procedure stc_info(in Tid char(8), in type int, out info varchar(10)) BEGIN IF type = 1 THEN set info = CAST((select count(Tno) from stc where Tno=Tid group by Tno) AS CHAR); ELSEIF type = 2 THEN set info = CAST((select AVG(Score) from stc where Tno=Tid group by Tno) AS CHAR); ELSE set info = 'error!!!'; END IF; END; ``` 在存储过程中,需要使用 BEGIN 和 END 来标记 IF 语句的开始和结束。此外,最后一个 ELSE 语句应该将 info 设置为 'error!!!',而不是将 type 设置为 'error!!!'。

create procedure stc_info(in Tid char(8), in type int, out info varchar(10)) BEGIN IF type = 1 then set info = CAST((select count(Tno) from stc where Tno=Tid group by Tno) AS CHAR); ELSEIF type = 2 then set info = CAST((select AVG(Score) from stc where Tno=Tid group by Tno) AS CHAR); ELSE set type = 'error!!!'; end if; END;

这个存储过程的语法是正确的,它的作用是根据传入的 Tid 和 type 参数,返回不同的统计信息。如果 type = 1,则返回 Tid 对应的 stc 表中记录的数量;如果 type = 2,则返回 Tid 对应的 stc 表中 Score 字段的平均值;否则返回 'error!!!'。 需要注意的是,在存储过程中,应该使用 BEGIN 和 END 来标记代码块的开始和结束,这样可以避免语法错误。此外,最后一个 ELSE 语句应该将 info 设置为 'error!!!',而不是将 type 设置为 'error!!!'。

相关推荐

void Dealwith_RS232(void) //RS485 is also handled at here { //stc_ring_buf_t *pstcBuffRing_Rcv = &g_stcBuffRing_Remote232_Rcv; _stc_rs232_info *pstcUart; //_stc_rs232_info *pstcRS232 = &g_stcRS232; uint8_t uart; for(uart=0; uart<2; uart++) //COM_RS232, COM_RS485 { if(COM_RS485 == uart) pstcUart = &g_stcRS485; else pstcUart = &g_stcRS232; if (pstcUart->unSend.u64Data)//if (g_stcRS232.unSend.u64Data) { pstcUart->State = STATE_REMOTE_SENDING; //g_stcRS232.State = STATE_REMOTE_SENDING; Dealwith_RS232_Send(uart);//Dealwith_RS232_Send(); } if (STATE_REMOTE_SENDING == pstcUart->State) break; //return; /* buffer ring pop out */ if (!BufferRing_RS232_Popout(uart, pstcUart))//if (!BufferRing_RS232_Popout(pstcBuffRing_Rcv, pstcRS232)) { return; } /* get cmd type and switch to branch */ switch(GetCmd_RS232(pstcUart))//switch(GetCmd_RS232(pstcRS232)) { case CMD_USER_GET_VERSION: RecvFromRS232_User_Get_Version(pstcUart);//RecvFromRS232_User_Get_Version(pstcRS232); break; case CMD_USER_GET_SN: RecvFromRS232_User_Get_SerialNbr(pstcUart);//RecvFromRS232_User_Get_SerialNbr(pstcRS232); break; #ifdef APP_LED case CMD_USER_STANDBY_IN: RecvFromRS232_User_Standby_In(pstcUart); break; case CMD_USER_STANDBY_OUT: RecvFromRS232_User_Standby_Out(pstcUart); break; case CMD_USER_BRIGHTNESS_GET: RecvFromRS232_User_Brightness_Get(pstcUart); break; case CMD_USER_BRIGHTNESS_SET: RecvFromRS232_User_Brightness_Set(pstcUart); break; case CMD_USER_BRIGHTNESS_DECREASE: RecvFromRS232_User_Brightness_Decrease(pstcUart); break; case CMD_USER_BRIGHTNESS_INCREASE: RecvFromRS232_User_Brightness_Increase(pstcUart); break; #endif case CMD_USER_DATE_SET: RecvFromRS232_User_Date_Set(pstcUart); break; case CMD_USER_DATE_GET: RecvFromRS232_User_Date_Get(pstcUart); break; case CMD_USER_TIME_SET: RecvFromRS232_User_Time_Set(pstcUart); break; case CMD_USER_TIME_GET: RecvFromRS232_User_Time_Get(pstcUart); break; case CMD_MFG_TEST: RecvFromRS232_Mfg_Test(pstcUart); break; case CMD_MFG_UPDATE_BOARD: RecvFromRS232_Mfg_Update_Board(pstcUart); break; case CMD_MFG_UPDATE_PANEL: RecvFromRS232_Mfg_Update_Panel(pstcUart); break; case CMD_MFG_EEPROM: RecvFromRS232_Mfg_Eeprom(pstcUart); break; case CMD_MFG_BEEPER: RecvFromRS232_Mfg_Beeper(pstcUart); break; case CMD_MFG_EXIT: RecvFromRS232_Mfg_Exit(pstcUart); break; //kk case CMD_OTA_INIT: RecvFromRS232_OTA_Init(pstcUart); break; default: RecvFromRS232_Invalid_Cmd_Param(pstcUart); break; } g_stcRS232.State = STATE_REMOTE_IDLE; return; } } 怎么让BufferRing_RS232_Popout(uart, pstcUart)时,要等到uart=1时,才能return

解释以下代码:#include "stc32g.h" #include "intrins.h " #define uchar unsigned char void main() { char CY1,CY2,CY3; EAXFR=1; CKCON=0x00; WTST=0x00; CKCON =0x00; WTST= 0x00; P0M0 = 0x00; P0M1 = 0x00; P1M0= 0x00; P1M1= 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1= 0x00; while (1){ P33=1; _nop_(); _nop_(); CY1=P33; P14=1; _nop_(); _nop_(); CY2=P14; P15=1; _nop_(); _nop_(); CY3=P15; if(CY1==1&&CY2==0&&CY3==1){ PWMA_CCER1=0x00; PWMA_CCMR1 =0x60; PWMA_CCMR2 =0x60; PWMA_CCER1= 0x11; PWMA_CCR1H = 0x17; PWMA_CCR1L= 0x00; PWMA_CCR2H = 0x17; PWMA_CCR2L= 0x00; PWMA_ARRH= 0x6f; PWMA_ARRL= 0x00; PWMA_ENO=0x05; PWMA_PS=0x0A; PWMA_BKR= 0x80; PWMA_CR1=0x01; } if(CY1==0&&CY2==1&&CY3==1){ PWMA_CCER1=0x00; PWMA_CCMR1 =0x60; PWMA_CCMR2 =0x60; PWMA_CCER1= 0x11; PWMA_CCR1H = 0x10; PWMA_CCR1L= 0x00; PWMA_CCR2H = 0x17; PWMA_CCR2L= 0x00; PWMA_ARRH= 0x6f; PWMA_ARRL= 0x00; PWMA_ENO=0x05; PWMA_PS=0x0A; PWMA_BKR= 0x80; PWMA_CR1=0x01; } if(CY1==1&&CY2==1&&CY3==0){ PWMA_CCER1=0x00; PWMA_CCMR1 =0x60; PWMA_CCMR2 =0x60; PWMA_CCER1= 0x11; PWMA_CCR1H = 0x17; PWMA_CCR1L= 0x00; PWMA_CCR2H = 0x10; PWMA_CCR2L= 0x00; PWMA_ARRH= 0x6f; PWMA_ARRL= 0x00; PWMA_ENO=0x05; PWMA_PS=0x0A; PWMA_BKR= 0x80; PWMA_CR1=0x01; } if(CY1==0&&CY2==0&&CY3==0){ PWMA_CCER1=0x00; PWMA_CCMR1 =0x60; PWMA_CCMR2 =0x60; PWMA_CCER1= 0x11; PWMA_CCR1H = 0x00; PWMA_CCR1L= 0x00; PWMA_CCR2H = 0x00; PWMA_CCR2L= 0x00; PWMA_ARRH= 0x6f; PWMA_ARRL= 0x00; PWMA_ENO=0x05; PWMA_PS=0x0A; PWMA_BKR= 0x80; PWMA_CR1=0x01; } if(CY1==1&&CY2==1&&CY3==1){ PWMA_CCER1=0x00; PWMA_CCMR1 =0x60; PWMA_CCMR2 =0x60; PWMA_CCER1= 0x11; PWMA_CCR1H = 0x17; PWMA_CCR1L= 0x00; PWMA_CCR2H = 0x17; PWMA_CCR2L= 0x00; PWMA_ARRH= 0x6f; PWMA_ARRL= 0x00; PWMA_ENO=0x05; PWMA_PS=0x0A; PWMA_BKR= 0x80; PWMA_CR1=0x01; } }}

最新推荐

recommend-type

STC8H系列单片机技术参考手册-20200826.pdf

STC8H1K系列、STC8H2K系列、STC8H3K系列、STC8H8K系列单片机技术参考手册,STC宏晶科技深圳国芯人工智能有限公司官方文件。,
recommend-type

STC8H8K64U原理图(上)

STC8H8K64U原理图(上)
recommend-type

STC单片机 IAP(EEPROM)的使用

STC89C51、52内部都自带有2K字节的EEPROM,54、55和58都自带有16K字节的EEPROM,STC单片机是利用IAP技术实现的EEPROM,内部Flash擦写次数可达100,000 次以上,先来介绍下ISP与IAP的区别和特点。
recommend-type

如何编写STC单片机的ISP协议

本文即介绍此情况下的ISP(In-System-Programming)程序设计方法,以及在SST和STC单片机上的具体实现.。
recommend-type

STC12C5A60S2中的AD转换

AD里面包含da,当输入电压Vin时,da的最高位是1,即为0.5Vref与输入信号比较,如果输入大于0.5Vref则比较器输出为1,同时da的最高位为1,反之DA最高位则为0,通过8次比较后得到8个01数据即完成ad转换。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用matlab绘制高斯色噪声情况下的频率估计CRLB,其中w(n)是零均值高斯色噪声,w(n)=0.8*w(n-1)+e(n),e(n)服从零均值方差为se的高斯分布

以下是用matlab绘制高斯色噪声情况下频率估计CRLB的代码: ```matlab % 参数设置 N = 100; % 信号长度 se = 0.5; % 噪声方差 w = zeros(N,1); % 高斯色噪声 w(1) = randn(1)*sqrt(se); for n = 2:N w(n) = 0.8*w(n-1) + randn(1)*sqrt(se); end % 计算频率估计CRLB fs = 1; % 采样频率 df = 0.01; % 频率分辨率 f = 0:df:fs/2; % 频率范围 M = length(f); CRLB = zeros(M,1); for
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。