我的存储过程语法有什么问题? [英] What is wrong in my stored procedure syntax?
问题描述
我收到此错误:
错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'NULL'附近使用
ERROR 1064 (42000): 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 'NULL' at line 1
我正在使用存储过程来检索数据,在这种情况下,我正在使用分页
I am using stored procedure to retrieve data and in this I am using pagination
这是我的存储过程代码:
Here is my stored procedure code :
CREATE DEFINER=`root`@`%` PROCEDURE `usp_get_product_wall_details`(
IN `in_user_id` INT,
IN `in_product_name` VARCHAR(50),
IN `in_category_id` INT
,
IN `in_order_by` VARCHAR(50),
IN `in_order_type` VARCHAR(50),
IN `in_page_no` INT,
IN `in_limit` INT
)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
BEGIN
DECLARE var_offset INT;
DECLARE var_limit INT DEFAULT 10;
IF in_limit != 0 THEN
set var_limit = in_limit;
END IF;
set var_offset = (in_page_no - 1) * var_limit;
set @sql = '';
set @query = '';
set @query= concat("select SQL_CALC_FOUND_ROWS p.id,p.product_name,p.seller_count,p.rating,p.rating_count,pii.image_url,
padem.product_mrp,padem.minimum_selling_price,max(padem.discount_price) as discount_price,
max(padem.discount_percentage) as discount_percentage,pade.enum_value,padem.id as enum_id
from product p
inner join abc padem on padem.product_id = p.id
INNER JOIN cd pii ON padem.product_id = pii.product_id
inner join ef pade on pade.id = padem.attribute_dropdown_enum_id
where p.`status` = 1 and pii.is_thumbnail = 1 and padem.seller_id is not null and
pii.enum_mapping_id = (select pad.id from product_attribute_dropdown_enum_mapping pad where pad.product_id = padem.product_id and
pad.attribute_dropdown_enum_id = padem.attribute_dropdown_enum_id and pad.seller_id is null) and
padem.sort_order = (select min(sort_order) from product_attribute_dropdown_enum_mapping where product_id = padem.product_id group by product_id)
and (p.product_name like concat('tropicana','%') or p.product_name like concat('%','tropicana','%'))
group by p.id
order by ",in_order_by," ",in_order_type," limit ", var_offset,",",var_limit);
set @sql = concat(@sql,@query);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
执行此过程时出现错误.
When I execute this procedure I am getting the error.
但是同时,如果我在存储过程之外使用一些静态数据运行简单查询,则可以完美地检索数据.
But at the same time if I run simple query outside the stored procedure with some static data, I can retrieve the data perfectly.
表名已更改
推荐答案
我通过重启MySQL服务器找到了解决方案:
I have found the solution by restarting MySQL server:
sudo service mysql restart
这篇关于我的存储过程语法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!