The UNPIVOT operation retrieves data from columns and transposes the data into rows.
Execution Plan image:
The UPDATE statement modifies existing data within a database table. It has the following basic form:
UPDATE table_expression
SET [(]column_expression=value_expression
[,column_expression=value_expression&ldots;]
[)]
WHERE where_condition
table_expression
Specifies the table, partition, view, subquery, or table collection that is to have its rows updated into which rows are inserted.
column_expression
Consists of either a single column name or a list of columns enclosed in parentheses. Using a column list is convenient when setting multiple columns to the values returned by a subquery. As illustrated in the following:
UPDATE employees c
SET (manager_id,department_id)=
(SELECT manager_id,department_id
FROM departments
WHERE department_name=’BOSTON’)
WHERE employee_id=1234
where_condition
Is a standard WHERE clause. It can include subqueries.
A correlated update includes a sub-query that contains references to columns in the table being updated. The query is evaluated for each row that is eligible for update. The correlated update is very similar to the correlated sub-query described earlier. The following statement executes a correlated update: the sub-query within the SELECT statement is executed once for each row in CUSTOMERS which satisfies the WHERE clause:
UPDATE customers c
SET sales_rep_id=
(SELECT manager_id
FROM employees
WHERE surname=c.contact_surname
AND firstname=c.contact_firstname
AND date_of_birth=c.date_of_birth)
WHERE (contact_surname,contact_firstname,date_of_birth)
IN (SELECT surname,firstname,date_of_birth
FROM employees)
Execution Plan image:
Set operation.
VIEW resolves any query nested deeper than the VIEW operation into a temporary area. The use of VIEW may be caused by correlated queries or by the inability of Oracle to pull a view’s query into the rest of a larger query, forcing it to resolve the view separately.
The example is in two parts: a view is created and then queried. The plan that follows applies only to the query of the view, not to the view creation itself.
create view COMPANY_COUNT as
select Zip, COUNT(*) Company_Count
from COMPANY
group by Zip;
select Zip, Company_Count
from COMPANY_COUNT
where Company_Count BETWEEN 10 and 20;
VIEW COMPANY_COUNT
FILTER
SORT GROUP BY
TABLE ACCESS FULL COMPANY
Because there is a set operation (SORT GROUP BY) within the view syntax, the optimizer must resolve the view before executing the conditions specified in the query. All the rows are fetched from COMPANY table using a full table scan, then they are sorted and counted by Zip during the SORT GROUP BY operation. The WHERE clause condition in the query is applied during the FILTER operation on the result of the view.
The VIEW PUSHED PREDICATE operation pushes predicates into a temporary table used for storing query results.
© ALL RIGHTS RESERVED. Termini di utilizzo Privacy Cookie Preference Center