调用存储过程报错 MySQL server version for the right syntax to use near ‘NULL‘ at line 1

参见写过的MySQL存储过程:MySQL存储过程删除历史数据_tabvla的博客-CSDN博客

在代码运行过程中,调用存储过程 call p_test("column name"); 反复遇到报错MySQL server version for the right syntax to use near 'NULL' at line 1,存储过程中相关代码部分如下:

	DECLARE done INT DEFAULT FALSE;
	DECLARE field_1 INT (11);
	DECLARE p1 INT(11);
	
	DECLARE cur_list CURSOR FOR (SELECT * FROM view_1);
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
	DROP VIEW IF EXISTS view_1;
	SET @strSql = CONCAT("CREATE VIEW view_1 as SELECT id from table1 WHERE column_1 = '", column1,"'");
	PREPARE stmt FROM @strSql;  
    EXECUTE stmt;  
    DEALLOCATE PREPARE stmt; 

重点排查@strSql,当使用PREPARE时,如果sql语句中出现NULL,会导致报错,加入传参判断,完善CONCAT写法,顺利解决问题

  SET @strSql = "CREATE VIEW view_1 as SELECT id FROM table1";
	IF column1 IS NOT NULL THEN
		SET @strSql = CONCAT(@strSql, " WHERE column_1 = '", column1,"'");
    END IF;
  PREPARE stmt FROM @strSql;  
  EXECUTE stmt;  
  DEALLOCATE PREPARE stmt; 

还挺意外,搜索了一下调用存储过程报null的错误非常常见,大概看了一下基本都是sql语句中NULL判断不够完善导致有可能出现空值,基本把空值可能性扼杀了问题就解决了,纠结怎么调用是没用的,问题出在存储过程里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个误信息"check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line "是指在你MySQL语句中存在语误,需要根据你的MySQL服务器版本来使用正确的语法。 这个误通常发生在SQL语句的某一行的附近。具体的语法误需要根据你的SQL语句来确定,可能是缺少了某个关键字、拼写误、或者误使用了某个符号。你可以参考MySQL的官方文档来查找正确的语法,并且确保你的SQL语句与你的MySQL服务器版本兼容。可以尝试使用调试工具来逐行检查你的SQL语句,找出误所在并进行修正。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [check the manual that corresponds to your MySQL server version for the right syntax to use near](https://blog.csdn.net/cdliker/article/details/106815722)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [your MySQL server version for the right syntax to use near ‘(0) NOT NULL, `endTime` datetime(0) NO](https://download.csdn.net/download/weixin_38515573/13688019)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [check the manual that corresponds to your MySQL server version for the right syntax to use near解决...](https://blog.csdn.net/qq_35623773/article/details/109752080)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值