2

この Oracle クエリを SQL Server 2008 用に書き直そうとしています。

UPDATE "LOAD"."UNITS_OF_MEASURE" 
SET ("UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE", "UOM_REFERENCE", "UOM_SUBTYPE_ID") =
                 ( SELECT "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE", 0 AS "UOM_REFERENCE", NULL AS "UOM_SUBTYPE_ID"
                    FROM ( SELECT DISTINCT "UOM_TYPE_ID", "UOM_CODE", "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE"
                            FROM "LOAD"."LOADER_UNITS_OF_MEASURE"
                            INNER JOIN "LOAD"."UOM_TYPES" ON ("UOM_TYPES"."UOM_TYPE_CODE"="LOADER_UNITS_OF_MEASURE"."UOM_TYPE_CODE")
                         ) SELECTION
                    WHERE ("SELECTION"."UOM_TYPE_ID"="UNITS_OF_MEASURE"."UOM_TYPE_ID")
                    AND ("SELECTION"."UOM_CODE"="UNITS_OF_MEASURE"."UOM_CODE")
                )
WHERE EXISTS  ( SELECT "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE", 0 AS "UOM_REFERENCE", NULL AS "UOM_SUBTYPE_ID"
                  FROM ( SELECT DISTINCT "UOM_TYPE_ID", "UOM_CODE", "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE"
                          FROM "LOAD"."LOADER_UNITS_OF_MEASURE"
                          INNER JOIN "LOAD"."UOM_TYPES" ON ("UOM_TYPES"."UOM_TYPE_CODE"="LOADER_UNITS_OF_MEASURE"."UOM_TYPE_CODE")
                        ) SELECTION
                 WHERE ("SELECTION"."UOM_TYPE_ID"="UNITS_OF_MEASURE"."UOM_TYPE_ID")
                 AND ("SELECTION"."UOM_CODE"="UNITS_OF_MEASURE"."UOM_CODE")
)

クエリは DBMS に依存しないクエリ ビルダー レイヤーによって自動的に構成されるため、内部SELECTクエリは同じままにする必要があります。

とりわけ、次の構文を試しました。

UPDATE "LOAD"."UNITS_OF_MEASURE" 
SET "UOM_DESC" = i."UOM_DESC", "UOM_SYMBOL" = i."UOM_SYMBOL", "UOM_MUL_FACTOR" = i."UOM_MUL_FACTOR", "UOM_ADD_FACTOR" = i."UOM_ADD_FACTOR", "UOM_DEC_PLACE" = i."UOM_DEC_PLACE",
     "UOM_REFERENCE" = 0, "UOM_SUBTYPE_ID" = NULL FROM
                 ( SELECT "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE", 0 AS "UOM_REFERENCE", NULL AS "UOM_SUBTYPE_ID"
                    FROM ( SELECT DISTINCT "UOM_TYPE_ID", "UOM_CODE", "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE"
                            FROM "LOAD"."LOADER_UNITS_OF_MEASURE"
                            INNER JOIN "LOAD"."UOM_TYPES" ON ("UOM_TYPES"."UOM_TYPE_CODE"="LOADER_UNITS_OF_MEASURE"."UOM_TYPE_CODE")
                         ) SELECTION
                    WHERE ("SELECTION"."UOM_TYPE_ID"="UNITS_OF_MEASURE"."UOM_TYPE_ID")
                    AND ("SELECTION"."UOM_CODE"="UNITS_OF_MEASURE"."UOM_CODE")
                )i
WHERE EXISTS ( SELECT "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE", 0 AS "UOM_REFERENCE", NULL AS "UOM_SUBTYPE_ID"
                  FROM ( SELECT DISTINCT "UOM_TYPE_ID", "UOM_CODE", "UOM_DESC", "UOM_SYMBOL", "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE"
                          FROM "LOAD"."LOADER_UNITS_OF_MEASURE"
                          INNER JOIN "LOAD"."UOM_TYPES" ON ("UOM_TYPES"."UOM_TYPE_CODE"="LOADER_UNITS_OF_MEASURE"."UOM_TYPE_CODE")
                        ) SELECTION
                 WHERE ("SELECTION"."UOM_TYPE_ID"="UNITS_OF_MEASURE"."UOM_TYPE_ID")
                 AND ("SELECTION"."UOM_CODE"="UNITS_OF_MEASURE"."UOM_CODE")
)

残念ながら"UNITS_OF_MEASURE"."UOM_TYPE_ID""UNITS_OF_MEASURE"."UOM_CODE"9-10行目では解決できません。

4

1 に答える 1

3

基本的に、これは、派生テーブルを外部テーブル (UPDATE のターゲット) に結合するのではなく、外部テーブルと関連付けているように見えます。これは Transact-SQL では機能しません (実際のところ、これが Oracle で機能するかどうかも疑問です)。

ただし、次のようなUPDATE...FROM構文を使用できます。中間層の SELECT を削除し、最も内側の SELECT を派生テーブルとして使用して結合しますUNITS_OF_MEASURE。つまり、次のようになります。

UPDATE "LOAD"."UNITS_OF_MEASURE" 
SET "UOM_DESC" = "SELECTION"."UOM_DESC",
    "UOM_SYMBOL" = "SELECTION"."UOM_SYMBOL",
    "UOM_MUL_FACTOR" = "SELECTION"."UOM_MUL_FACTOR",
    "UOM_ADD_FACTOR" = "SELECTION"."UOM_ADD_FACTOR",
    "UOM_DEC_PLACE" = "SELECTION"."UOM_DEC_PLACE",
    "UOM_REFERENCE" = 0,
    "UOM_SUBTYPE_ID" = NULL
FROM ( SELECT DISTINCT "UOM_TYPE_ID", "UOM_CODE", "UOM_DESC", "UOM_SYMBOL",
                       "UOM_MUL_FACTOR", "UOM_ADD_FACTOR", "UOM_DEC_PLACE"
       FROM "LOAD"."LOADER_UNITS_OF_MEASURE"
       INNER JOIN "LOAD"."UOM_TYPES" ON ("UOM_TYPES"."UOM_TYPE_CODE"="LOADER_UNITS_OF_MEASURE"."UOM_TYPE_CODE")
     ) SELECTION
WHERE ("SELECTION"."UOM_TYPE_ID"="UNITS_OF_MEASURE"."UOM_TYPE_ID")
  AND ("SELECTION"."UOM_CODE"="UNITS_OF_MEASURE"."UOM_CODE")
;

SELECTIONこれにより、派生テーブルが結合され、"LOAD"."UNITS_OF_MEASURE"派生テーブルのデータを使用して他のテーブルの列が更新されます。

于 2013-05-27T13:28:33.440 に答える