当我尝试将其从** Access **转换为** Oracle **时,更新脚本会导致错误

时间:2014-08-25 17:10:16

标签: sql oracle ms-access converter

我正在尝试将某些查询转换为使用 Oracle 而不是访问,但一直未成功。我刚收到订单错了吗?或使用不正确的陈述。

这是剧本:

Error starting at line : 142 in command -
UPDATE CONTROL_RECORDS 
SET EXTRACT_WORK_001.BAY_CASEFLOW_SKU_COUNT =  
DECODE(-1, 
SIGN(0 - COMBINED_LAYER_QTY), 0, 
DECODE(-1, 
SIGN(0 - BAY_ACTIVITY), 
(DECODE(ADJUSTED_BAY_USPD*DAY_COUNT/BAY_ACTIVITY<=CASEFLOW_USPD_MAX,1,0)), 
0), 
EXTRACT_WORK_001.BULK_CASEFLOW_SKU_COUNT =  
DECODE(-1, 
SIGN(0 - COMBINED_LAYER_QTY), 0, 
DECODE(-1, 
SIGN(0 - BULK_ACTIVITY), 
DECODE(ADJUSTED_BULK_USPD*DAY_COUNT/BULK_ACTIVITY<=CASEFLOW_USPD_MAX,1,0)), 
0), 
EXTRACT_WORK_001.COMBINED_CASEFLOW_SKU_COUNT =  
DECODE(-1, 
SIGN(0 - COMBINED_LAYER_QTY), 0, 
DECODE(ADJUSTED_COMBINED_USPD<=CASEFLOW_USPD_MAX,1,0)) 
FROM CONTROL_RECORDS, EXTRACT_WORK_001 
WHERE (CONTROL_RECORDS.LOC_ID = EXTRACT_WORK_001.LOC_ID) 
AND   ((EXTRACT_WORK_001.COMBINED_LAYER_QTY)=0) 
Error at Command Line : 148 Column : 81 Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"

这是原始的Access查询:

UPDATE CONTROL_RECORDS INNER JOIN EXTRACT_WORK_001 
    ON CONTROL_RECORDS.LOC_ID = EXTRACT_WORK_001.LOC_ID 
SET 
    EXTRACT_WORK_001.BAY_CASEFLOW_SKU_COUNT = IIf(combined_layer_qty>0,0,IIf(bay_activity>0,IIf(adjusted_BAY_USPD*day_count/bay_activity<=caseflow_uspd_max,1,0),0)), 
    EXTRACT_WORK_001.BULK_CASEFLOW_SKU_COUNT = IIf(combined_layer_qty>0,0,IIf(bulk_activity>0,IIf(adjusted_BULK_USPD*day_count/bulk_activity<=caseflow_uspd_max,1,0),0)), 
    EXTRACT_WORK_001.COMBINED_CASEFLOW_SKU_COUNT = IIf(combined_layer_qty>0,0,IIf(adjusted_COMBINED_USPD<=caseflow_uspd_max,1,0))
WHERE (((EXTRACT_WORK_001.COMBINED_LAYER_QTY)=0));

请帮忙。我不喜欢什么方法或任何东西......只要它有效。

1 个答案:

答案 0 :(得分:1)

使用case更类似于iif而不是decode。您的许多表达都可以简化。另外,我认为在Oracle中的连接中没有直接的语法更新。

但是,假设表中定义了合理的主键和外键,则以下内容可能有效。如果您收到有关密钥保留表的错误,那么您需要提供有关表和关系的更多信息:

update (
    select
        w.bay_caseflow_sku_count,
        case when
            combined_layer_qty <= 0 and 
            bay_activity > 0 and 
            adjusted_bay_USPD * day_count <= bay_activity * caseflow_uspd_max
          then 1
          else 0
        end as new_bay,
        w.bulk_caseflow_sku_count,
        case when
            combined_layer_qty <= 0 and
            bulk_activity > 0 and
            adjusted_bulk_USPD * day_count <= bulk_activity * caseflow_uspd_max
          then 1
          else 0
        end as new_bulk,
        w.combined_caseflow_sku_count,
        case when
            combined_layer_qty <= 0 and
            adjusted_combined_USPD <= caseflow_uspd_max
          then 1
          else 0
        end as new_combined
    from
        extract_work_001 w
            inner join
        control_records c
            on c.loc_id = w.loc_id
    where 
        w.combined_layer_qty = 0
) t
set
    bay_caseflow_sku_count = new_bay,
    bulk_caseflow_sku_count = new_bulk,
    combined_caseflow_sku_count = new_combined;

Example SQLFiddle