问题
I am getting this error:
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.
Table names were changed
回答1:
I have found the solution by restarting MySQL server:
sudo service mysql restart
来源:https://stackoverflow.com/questions/55377468/what-is-wrong-in-my-stored-procedure-syntax