首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >过程的MySQL布尔值输入不能按预期工作

过程的MySQL布尔值输入不能按预期工作
EN

Stack Overflow用户
提问于 2012-01-04 11:57:05
回答 1查看 2.2K关注 0票数 0

我有一个接受一个布尔输入的过程:

代码语言:javascript
复制
 `get_storage_choices_expanded`(IN usage_total INT(11), IN no_request1 INT(8), IN no_request2 INT(8), IN reduced_redundancy_storage boolean)

但当我像这样使用它时:

代码语言:javascript
复制
call get_storage_choices_expanded(10,1,2,true);
select * from storage_choices_expanded
;

生成的结果与我测试过的同一select查询不匹配。例如:

代码语言:javascript
复制
(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
)

完整代码如下:

代码语言:javascript
复制
    -- --------------------------------------------------------------------------------
    -- 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,但似乎没有任何区别。

可以调用和运行该过程,没有错误,但结果是错误的。call procedure返回了reduced_redundancy_storage值为== 0的行,这是不正确的,因为它应该大于0

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-04 12:28:19

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8721823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档