Home > Database > Mysql Tutorial > How to Correctly Perform an UPDATE Query with INNER JOIN in Oracle?

How to Correctly Perform an UPDATE Query with INNER JOIN in Oracle?

Susan Sarandon
Release: 2025-01-25 04:50:09
Original
274 people have browsed it

How to Correctly Perform an UPDATE Query with INNER JOIN in Oracle?

In the Oracle, use Inner Join to correctly execute the update query

The following queries in MySQL can be successfully executed:

However, the same query in Oracle will cause the following errors:
<code class="language-sql">UPDATE table1
INNER JOIN table2 ON table1.value = table2.DESC
SET table1.value = table2.CODE
WHERE table1.UPDATETYPE='blah';</code>
Copy after login

Solution
<code>SQL错误:ORA-00933:SQL命令未正确结束
00933. 00000 -  "SQL command not properly ended"</code>
Copy after login

The syntax used in the query is invalid in Oracle. In order to meet the expected results, you can use one of the following methods:

The first method

This method uses sub -query to obtain the update value of table1.value according to the connection conditions. It ensures that only the matching line is updated.

The second method
<code class="language-sql">UPDATE table1 SET table1.value = (SELECT table2.CODE
                                  FROM table2 
                                  WHERE table1.value = table2.DESC)
WHERE table1.UPDATETYPE='blah'
AND EXISTS (SELECT table2.CODE
            FROM table2 
            WHERE table1.value = table2.DESC);</code>
Copy after login

This method uses an updated internal linkage diagram to execute the update. It requires Oracle to think that the internal linkage view is updated, depending on certain rules.

The above is the detailed content of How to Correctly Perform an UPDATE Query with INNER JOIN in Oracle?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template