2

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
)

3 Answers 3

6

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
        )
Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.