【问题标题】:MySQL Boolean input for Procedure does not work as expected程序的 MySQL 布尔输入未按预期工作
【发布时间】:2012-02-02 01:21:45
【问题描述】:

我有一个接受一个布尔输入的 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)

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

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

【问题讨论】:

  • 两个输出有什么区别?
  • 表中是否有名为“reduced_redundancy_storage”的字段?除了您在过程中定义的参数。

标签: java mysql boolean


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    相关资源
    最近更新 更多