2012-01-04 12 views
0

我有一個過程,需要一個布爾輸入不起作用與我測試過的相同的選擇查詢。例如MySQL的布爾輸入過程如預期

(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 

我試圖取代布爾,位,TINYINT(1),但它似乎沒有任何區別布爾。

該過程可以被調用並且運行時沒有錯誤,但結果是錯誤的。 調用過程返回的行與reduced_redundancy_storage值== 0這是不正確的,因爲它應該> 0

+0

兩個輸出之間有什麼區別? – 2012-01-04 04:32:14

+0

表中有一個名爲「reduced_redundancy_storage」的字段嗎?除了您在過程中定義的參數之外。 – 2012-01-04 04:36:23

回答

1

我認爲這裏的問題是你已經定義了存儲過程中的一個參數與數據庫中存在的字段相同的名稱。檢查字段是否存在「reduced_redundancy_storage」