5

I have a sql like this

UPDATE A
SET A.TEMSILCI_KOD = 4
FROM S_MUSTERI A, S_TEKLIF B
WHERE A.TEMSILCI_KOD = 9
AND B.BAYI_KOD = 17
AND A.HESAP_NO = B.HESAP_NO

But i getting an error like this

Error starting at line 8 in command:
UPDATE A
SET A.TEMSILCI_KOD = 4
FROM S_MUSTERI A, S_TEKLIF B
WHERE A.TEMSILCI_KOD = 9
AND B.BAYI_KOD = 17
AND A.HESAP_NO = B.HESAP_NO
Error at Command Line:9 Column:22
Error report:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

Where is the ERROR?

3
  • The multi-table UPDATE works on SQL Server, but not Oracle. Commented Feb 8, 2011 at 15:05
  • are you doing this in a procedure? Commented Feb 8, 2011 at 15:06
  • 3
    RTFM, there's no FROM. Commented Feb 8, 2011 at 15:07

3 Answers 3

11

Maybe something like

UPDATE S_MUSTERI
SET TEMSILCI_KOD = 4
WHERE TEMSILCI_KOD = 9
AND EXISTS (SELECT 1 FROM S_TEKLIF B
WHERE S_MUSTERI.HESAP_NO = B.HESAP_NO
AND B.BAYI_KOD = 17)
Sign up to request clarification or add additional context in comments.

Comments

4

In Oracle the syntax to update a view is different from SQL*Server's syntax. In Oracle you could issue the following query:

UPDATE (SELECT A.TEMSILCI_KOD
          FROM S_MUSTERI A, S_TEKLIF B
         WHERE A.TEMSILCI_KOD = 9
           AND B.BAYI_KOD = 17
           AND A.HESAP_NO = B.HESAP_NO)
   SET TEMSILCI_KOD = 4

Note: This query will only work in Oracle if (S_TEKLIF.BAYI_KOD, S_TEKLIF.HESAP_NO) is unique (so that the update will not be ambiguous and each row from S_MUSTERI will be updated at most once).

Comments

2

Your update statement does not follow the correct syntax. There is no from clause in the update statement. It should follow the format

Update <table> 
   set <column> = <value> 
 where <conditions>

See this documentation on update: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10007.htm#i2067715

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.