문제

I need this update query to run on both SQL Server and Oracle. Our Oracle version is 10.2 if that matters. When I run the query in Oracle I get "ERROR ORA-00933: SQL command not properly ended". What do I need to do to get this to run in Oracle?

UPDATE dbo.tableUpdate
SET fieldA = tt.fieldB
FROM dbo.tableTranslate tt
WHERE
    tt.fieldC = dbo.tableUpdate.fieldC
    AND
    tt.fieldD = dbo.tableUpdate.fieldA
    AND
    1 = (
        SELECT COUNT(tblTrans.fieldD) 
        FROM dbo.tableTranslate tblTrans
        WHERE 
            tblTrans.fieldC = dbo.tableUpdate.fieldC 
            AND 
            tblTrans.fieldD = dbo.tableUpdate.fieldA
)
도움이 되었습니까?

해결책

The UPDATE...FROM syntax is not valid for Oracle. You will need to use a subquery, like this:

UPDATE dbo.tableUpdate t
SET t.fieldA = (SELECT tt.fieldB
                FROM dbo.tableTranslate tt
                WHERE tt.fieldC = t.fieldC
                AND tt.fieldD = t.fieldA
               )
WHERE 1 = (
        SELECT COUNT(tblTrans.fieldD) 
        FROM dbo.tableTranslate tblTrans
        WHERE tblTrans.fieldC = t.fieldC 
        AND tblTrans.fieldD = t.fieldA
        )

다른 팁

The syntax for co-related sub query is a little different in Oracle.

UPDATE dbo.tableUpdate
SET fieldA = (select tt.fieldB
FROM dbo.tableTranslate tt
WHERE
    tt.fieldC = dbo.tableUpdate.fieldC
    AND
    tt.fieldD = dbo.tableUpdate.fieldA)
    AND
    1 = (
        SELECT COUNT(tblTrans.fieldD) 
        FROM dbo.tableTranslate tblTrans
        WHERE 
tblTrans.fieldC = dbo.tableUpdate.fieldC 
AND 
tblTrans.fieldD = dbo.tableUpdate.fieldA)

You will need to rewrite completely your query for Oracle. Some stuff that won't work in Oracle 10.2:

  1. from clause in update sentence (you will need to write a subselect for this)
  2. dbo schema, unless you actually have a user named dbo in oracle owning the table you are trying to update
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top