How to use the update statement in Oracle?
The UPDATE statement in Oracle is used to change the values of existing data in a table. Here is the basic syntax for an Oracle UPDATE statement:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
- Table_name: the name of the table to be updated.
- The names of the columns to be updated.
- Values 1, 2, etc.: values to be updated.
- WHERE condition: Optional condition used to specify which rows to update. If no WHERE condition is specified, all rows in the table will be updated.
Here is an example demonstrating how to update data in a table using the UPDATE statement.
UPDATE employees
SET salary = 5000, department = 'IT'
WHERE employee_id = 1001;
This example will update the salary and department values of the employee with employee_id 1001 in the employees table. The salary will be updated to 5000 and the department will be updated to ‘IT’.
Caution: When using the UPDATE statement, be sure to provide the correct conditions and values to avoid unintended data modifications.