2013-04-17 2 views
1

다른 테이블을 참조하여 테이블의 두 열을 업데이트하려고합니다. 스크립트를 실행하는 동안 오류가 표시됩니다.다른 테이블과 조인 된 테이블의 열을 업데이트하는 방법은 무엇입니까?

오류 : 오류는 명령 라인 1에서 시작 :

UPDATE wb_costing_work_items, 
     sa_sales_documents, 
     sa_sales_document_items 
    SET cwi_price_per_hour = sdi_price, 
     cwi_amount = sdi_price * cwi_hours 
WHERE cwi_lo_id = sad_lo_id 
    AND sdi_sad_id = sad_id 
    AND sdi_wit_id = cwi_wit_id 
    AND cwi_id = 1650833 

Error at Command Line:1 Column:28 Error report: SQL Error: ORA-00971: missing SET keyword 00971. 00000 - "missing SET keyword"

SQL 문 어쩌면이 같은

UPDATE wb_costing_work_items cwi, 
     sa_sales_documents sad, 
     sa_sales_document_items sdi 
    SET cwi.cwi_price_per_hour = sdi.sdi_price, 
     cwi.cwi_amount = sdi.sdi_price * cwi.cwi_hours 
WHERE cwi.cwi_lo_id = sad.sad_lo_id 
    AND sdi.sdi_sad_id = sad.sad_id 
    AND sdi.sdi_wit_id = cwi.cwi_wit_id 
    AND cwi.cwi_id = 1650855 
+0

업데이트 할 테이블을 선택하십시오. –

+0

테이블 wb_costing_work_items의 두 열을 업데이트하려고합니다. 다른 테이블에서 값을 가져와야합니다. –

답변

0

뭔가.

테이블이 정의되는 방법에 대한 정보를 포함하지 않았으므로 어떤 열이 어떤 테이블에 속해 있는지에 대해 몇 가지 추측을해야합니다.

아마도 내가 제대로 이해하지 못했고 실제 테이블 구조로 쿼리를 조정해야 할 것입니다.

merge into wb_costing_work_items 
using 
(
    select cwi.pk_column, -- don't know what the PK of the wb_costing_work_items is due to lack of information 
      sdi.sdi_price, -- don't know if this column really belong to this table 
      sdi.sdi_price * cwi.cwi_hours as total-- again unsure about column names due to lack of information 
    FROM wb_costing_work_items cwi 
     JOIN sa_sales_documents sad ON sad.sad_lo_id = cwi.cwi_lo_id -- not sure about these, due to lack of information 
     JOIN sa_sales_document_items sdi 
     ON sdi.sad_id = sad.sdi_sad_id  -- not sure about these, due to lack of information 
     AND sdi.sdi_wit_id = cwi.cwi_wit_id -- not sure about these, due to lack of information 

) t ON (t.pk_column = w.pk_column) -- not sure about this, due to lack of information 
when matched then 
update 
    set cwi_price_per_hour = t.sdi_price, 
     cwi_amount = t.total; 
+0

자, 테스트 해 보겠습니다. –

+0

여기에 별칭 "w"가 표시됩니까? –

+0

감사합니다! 그 작품! –

1

이것은 확실히 작동합니다.

  UPDATE (SELECT cwi_price_per_hour, 
          sdi_price, 
          cwi_amount, 
          sdi_price, 
          cwi_hours 
         FROM wb_costing_work_items, 
          sa_sales_documents, 
          sa_sales_document_items 
        WHERE  cwi_lo_id = sad_lo_id 
          AND sdi_sad_id = sad_id 
          AND sdi_wit_id = cwi_wit_id 
          AND cwi_id = 1650833) 
       SET cwi_price_per_hour = sdi_price, cwi_amount = sdi_price * cwi_hours 

검색어를 쉽게 읽을 수 있도록 사용 된 테이블의 별명을 지정하고 프리픽스 열을 지정하십시오.

+0

오류를 표시하는 문을 실행하려고합니다. 줄 : 12 열 : 19 오류 보고서 : SQL 오류 : ORA-01779 : 키가 아닌 테이블에 매핑되는 열을 수정할 수 없습니다. 01779. 00000 - "수정할 수 없습니다 키 저장되지 않은 테이블에 매핑되는 열 " * 원인 : 이 키가 아닌 테이블에 매핑되는 조인보기의 열을 삽입하거나 업데이트하려고했습니다. * 조치 : 기본 기본 테이블을 직접 수정하십시오. –

관련 문제