Update - (Oracle Query)
The UPDATE statement in Oracle SQL is used to modify existing records in a table. It allows you to change the values of one or more columns for a specific set of rows.
Syntax
The basic syntax for updating data in Oracle SQL is as follows:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Here, table_name
is the name of the table you want to update, column1
, column2
, etc. are the names of the columns you want to modify, and value1
, value2
, etc. are the new values you want to set. The WHERE
clause is used to specify which rows to update.
Example
For example, suppose we have a table called employees
with columns employee_id
, first_name
, last_name
, email
, and salary
. We want to increase the salary of all employees with a salary less than $50,000 by 10%.
UPDATE employees
SET salary = salary * 1.1
WHERE salary < 50000;
Output
The output of the update statement will be the number of rows affected by the update.
Explanation
In the above example, we have used the UPDATE
statement to modify the salary
column for all rows in the employees
table where the salary
is less than $50,000
. We have set the new value of the salary
column to be the original value multiplied by 1.1
, effectively increasing the salary by 10%.
Use
The UPDATE
statement is used whenever we need to modify existing records in a table. This can be useful when we need to correct errors or update old data with new information.
Important Points
- The
UPDATE
statement is used to modify existing records in a table. - The
SET
keyword is used to specify which columns to modify and what values to set them to. - The
WHERE
keyword is used to specify which rows to update.
Summary
In summary, the UPDATE
statement in Oracle SQL is used to modify existing records in a table. It allows you to change the values of one or more columns for a specific set of rows. By using the WHERE
clause, you can limit the scope of the update to only certain rows in the table. The UPDATE
statement is a powerful tool for correcting errors or updating old data with new information.