Oracle Database 23c introduces a host of powerful features aimed at enhancing database performance and query optimization. Among these innovations, Direct Join stands out as an efficient mechanism to streamline update and delete operations involving multiple related tables.
23c now allows you to use direct joins to other tables in UPDATE and DELETE statements in the FROM clause, in this article we will use SQL code examples to HR schema, so you can practice and learn it.
The main benefit is to make the coding of these Direct Joins simpler, using less code and more readable for SQL developers.
Scenario 1: Updating Salaries based on Department and City
Consider the scenario where we need to update the salaries of employees working in the Marketing department in the city of Toronto by increasing their salaries by 10%.
Prior to Oracle Database 23c, we might have used a query similar to this:
Once we identify the records that need to be updated, we proceed to design our UPDATE statement to modify only those records. Therefore, in Oracle versions prior to 23c, the filter used in the UPDATE statement is quite similar to the filter used in the SELECT statement.
Prior to Oracle Database 23c, the common approach to formulate the UPDATE statement involved employing an inner query within the WHERE clause.
However, in 23c, we can harness the power of Direct Join to optimize this update operation:
By utilizing Direct Join, we simplify the query, eliminate subqueries, and improve overall performance.
Scenario 2: Delete employee Neena's job history where she worked as AC_ACCOUNT
Suppose we need to delete employee Neena's job history where she worked as AC_ACCOUNT.
Prior to Oracle Database 23c, we might have used a query similar to this:
Once we identify the records that need to be deleted, we proceed to design our DELETE statement to remove only those records. Therefore, in prior to 23c, the filter used in the DELETE statement is quite similar to the filter used in the SELECT statement.
Prior to Oracle Database 23c, the common approach to formulating the DELETE statement involved employing a subquery or inner query within the WHERE clause.
However, 23c, we can harness the power of Direct Join to optimize this DELETE operation:
Source: oracle.com
0 comments:
Post a Comment