You use the UPDATE statement to change rows in a table. Normally, when you use the UPDATE statement, you specify the following information:
The table containing the rows that are to be changed
A WHERE clause that specifies the rows that are to be changed
A list of column names , along with their new values, specified using the SET clause
You can change one or more rows using the same UPDATE statement. If more than one row is specified, the same change will be implemented for all of those rows. The following statement updates the last_name column to Orange for the row in the customers table whose customer_id column is 2:
SQL> UPDATE customers 2 SET last_name = 'Orange' 3 WHERE customer_id = 2; 1 row updated.
SQL*Plus confirms that one row was updated.
Caution | If you forget to add a WHERE clause, all the rows will be updated. This is typically not the result you want. |
Notice that the SET clause is used in the previous UPDATE statement to specify the column and the new value for that column. You can confirm the previous UPDATE statement did indeed change customer #2 s last name using the following query:
SQL> SELECT * 2 FROM customers 3 WHERE customer_id = 2; CUSTOMER_ID FIRST_NAME LAST_NAME DOB PHONE ----------- ---------- ---------- --------- ------------ 2 Cynthia Orange 05-FEB-68 800-555-1212