如何使用多个命名参数调用MySQL 8存储过程?

问题描述 投票:0回答:1

看着这个很老的树枝 MySQL 中存储过程的命名参数

我尝试使用多个参数调用 mysql 8 存储过程:

create definer = lardev@localhost procedure sp_getFilteredProductsWithDiscounts(IN in_status varchar(1), IN in_discountPriceAllowed tinyint unsigned, IN in_in_stock varchar(1), IN in_stock_qty mediumint, IN in_discounts_qty mediumint)
BEGIN


SELECT products.id, products.title, products.sale_price,
    GROUP_CONCAT(CONCAT(discounts.name, ': ', discounts.min_qty, ': ', discounts.max_qty, ': ', discounts.percent)) AS discount_info
FROM products
    LEFT JOIN discount_product ON discount_product.product_id = products.id
    LEFT JOIN discounts on discounts.id = discount_product.discount_id
    WHERE ( products.status = in_status OR ISNULL(in_status) ) AND
      ( products.discount_price_allowed = in_discountPriceAllowed OR ISNULL(in_discountPriceAllowed)) AND
      ( products.in_stock = 1 OR ISNULL(in_in_stock) ) AND
      ( products.stock_qty >= in_stock_qty OR ISNULL(in_stock_qty) ) AND
      ( in_discounts_qty BETWEEN discounts.min_qty  AND discounts.max_qty OR ISNULL(in_discounts_qty))
    -- from 200 till 300
    GROUP BY products.id, products.title, products.sale_price;

END;

并在 phpstorm 2023 中使用命名参数进行调用:

CALL sp_getFilteredProductsWithDiscounts(@in_status := 'A', @in_discountPriceAllowed := 1, @in_in_stock := 1, @in_stock_qty := 2, @in_discounts_qty := 3 );

我遇到错误:

[HY000][1267] Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='

看起来像:

为什么我收到此错误以及如何修复它?

php mysql stored-procedures
1个回答
0
投票

该错误基本上是说您正在尝试比较具有不同编码的两个值。您可以动态编码一个值,只需检查 MySQL 文档,对两侧进行相同的编码,就可以了。

您必须查看这些列,看看哪些是您比较的,哪些是不同的。

© www.soinside.com 2019 - 2024. All rights reserved.