程序的 MySQL 布尔输入未按预期工作

发布于 2024-12-24 20:25:39 字数 2727 浏览 0 评论 0原文

我有一个需要一个布尔输入的过程:

 `get_storage_choices_expanded`(IN usage_total INT(11), IN no_request1 INT(8), IN no_request2 INT(8), IN reduced_redundancy_storage boolean)

但是当我像这样使用它时:

call get_storage_choices_expanded(10,1,2,true);
select * from storage_choices_expanded
;

生成的结果与我测试过的相同选择查询不匹配。例如

(select *, 
    usage_each_plan * if(true,reduced_redundancy_storage, standard_storage) as price_storage, 
    concat_ws(' ',`Provider Name`,`Name`,`region_name`) as group_name,
    1 * request_group1_unit as "Number of Type1 Requests",
    2 * request_group2_unit as "Number of Type2 Requests",
    (1 * request_group1_price) as price_request1,
    (2 * request_group2_price) as price_request2
from 
  (SELECT *, 
    ( if((quota_band_high is not NULL) and 10>quota_band_high, quota_band_high, 10) - quota_band_low) as usage_each_plan
  FROM `cloud`.`storage_service_price`
  where 10 > quota_band_low and reduced_redundancy_storage > if(true,0, -1)
  ) as storage_usage_each_plan
)

完整代码如下:

    -- --------------------------------------------------------------------------------
    -- Routine DDL
    -- --------------------------------------------------------------------------------
    DELIMITER $$

    CREATE DEFINER=`root`@`localhost` PROCEDURE `get_storage_choices_expanded`(IN usage_total INT(11), IN no_request1 INT(8), IN no_request2 INT(8), IN reduced_redundancy_storage boolean)
    BEGIN

    drop table if exists `cloud`.`storage_choices_expanded`;
    CREATE TEMPORARY TABLE `cloud`.`storage_choices_expanded` AS

      (select *, 
          usage_each_plan * if(reduced_redundancy_storage,reduced_redundancy_storage, standard_storage) as price_storage, 
          concat_ws(' ',`Provider Name`,`Name`,`region_name`) as group_name,
          no_request1 * request_group1_unit as "Number of Type1 Requests",
          no_request2 * request_group2_unit as "Number of Type2 Requests",
          (no_request1 * request_group1_price) as price_request1,
          (no_request2 * request_group2_price) as price_request2
      from 
        (SELECT *, 
          ( if((quota_band_high is not NULL) and usage_total>quota_band_high, quota_band_high, usage_total) - quota_band_low) as usage_each_plan
        FROM `cloud`.`storage_service_price`
        where usage_total > quota_band_low and reduced_redundancy_storage > if(reduced_redundancy_storage,0, -1)
        ) as storage_usage_each_plan
      ) 


    ;
    END

我尝试用 bool、bit、TINYINT(1) 替换 boolean,但似乎没有任何区别。

程序可以调用并运行,没有错误,但结果是错误的。 调用过程返回 reduced_redundancy_storage 值 == 0 的行,这是不正确的,因为它应该是 >0

I have a PROCEDURE that takes one Boolean input:

 `get_storage_choices_expanded`(IN usage_total INT(11), IN no_request1 INT(8), IN no_request2 INT(8), IN reduced_redundancy_storage boolean)

But when I use it like:

call get_storage_choices_expanded(10,1,2,true);
select * from storage_choices_expanded
;

The result produced does not match with the same select query I have tested with. e.g.

(select *, 
    usage_each_plan * if(true,reduced_redundancy_storage, standard_storage) as price_storage, 
    concat_ws(' ',`Provider Name`,`Name`,`region_name`) as group_name,
    1 * request_group1_unit as "Number of Type1 Requests",
    2 * request_group2_unit as "Number of Type2 Requests",
    (1 * request_group1_price) as price_request1,
    (2 * request_group2_price) as price_request2
from 
  (SELECT *, 
    ( if((quota_band_high is not NULL) and 10>quota_band_high, quota_band_high, 10) - quota_band_low) as usage_each_plan
  FROM `cloud`.`storage_service_price`
  where 10 > quota_band_low and reduced_redundancy_storage > if(true,0, -1)
  ) as storage_usage_each_plan
)

The full code is as follows:

    -- --------------------------------------------------------------------------------
    -- Routine DDL
    -- --------------------------------------------------------------------------------
    DELIMITER $

    CREATE DEFINER=`root`@`localhost` PROCEDURE `get_storage_choices_expanded`(IN usage_total INT(11), IN no_request1 INT(8), IN no_request2 INT(8), IN reduced_redundancy_storage boolean)
    BEGIN

    drop table if exists `cloud`.`storage_choices_expanded`;
    CREATE TEMPORARY TABLE `cloud`.`storage_choices_expanded` AS

      (select *, 
          usage_each_plan * if(reduced_redundancy_storage,reduced_redundancy_storage, standard_storage) as price_storage, 
          concat_ws(' ',`Provider Name`,`Name`,`region_name`) as group_name,
          no_request1 * request_group1_unit as "Number of Type1 Requests",
          no_request2 * request_group2_unit as "Number of Type2 Requests",
          (no_request1 * request_group1_price) as price_request1,
          (no_request2 * request_group2_price) as price_request2
      from 
        (SELECT *, 
          ( if((quota_band_high is not NULL) and usage_total>quota_band_high, quota_band_high, usage_total) - quota_band_low) as usage_each_plan
        FROM `cloud`.`storage_service_price`
        where usage_total > quota_band_low and reduced_redundancy_storage > if(reduced_redundancy_storage,0, -1)
        ) as storage_usage_each_plan
      ) 


    ;
    END

I have tried to replace boolean with bool, bit, TINYINT(1), but it doesn't seem to make any difference.

The procedure can be called and run with no error, but the results are wrong.
call procedure returned rows with reduced_redundancy_storage value == 0 which is incorrect as it should be >0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪之触 2024-12-31 20:25:39

我认为这里的问题是您在存储过程中定义了一个与数据库中存在的字段同名的参数。检查是否存在名为“reduced_redundancy_storage”的字段。

I think the issue here is you have defined a parameter in stored procedure with the same name of a field exists in the database. Check whether a field exists with the name "reduced_redundancy_storage".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文