ORACLE | ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
|
Oracle - Update
In Oracle, UPDATE query is used to update the existing records in a table.we can update a table in 2 ways.
UPDATE table
SET column1 = expression1,
column2 = expression2,
...
column_n = expression_n
WHERE conditions;
UPDATE table1
SET column1 = (SELECT expression1
FROM table2
WHERE conditions)
WHERE conditions;
UPDATE suppliers
SET supplier_name = 'Kingfisher'
WHERE supplier_id = 2;
This example will update the supplier_name as "Kingfisher" where "supplier_id" is 2.
The following example specifies how to update multiple columns in a table. In this example, two columns supplier_name and supplier_address is updated by a single statement.
UPDATE suppliers
SET supplier_address = 'Agra',
supplier_name = 'Bata shoes'
WHERE supplier_id = 1;
1 row(s) updated.
0.06 seconds
UPDATE customers
SET name = (SELECT supplier_name
FROM suppliers
WHERE suppliers.supplier_name = customers.name)
WHERE age < 25;
2 row(s) updated.
0.02 seconds
Here, the customers table is updated by fetching the data from "suppliers" table.