Wednesday 23 November 2016

Update with select in Oracle


 

In this article, I'll show you how you can update data from table to another with select statement.

 

--1--create two table.

CREATE TABLE LOCAT001 AS (SELECT LOCATION_ID, STREET_ADDRESS, STATE_PROVINCE FROM LOCATIONS ); alter table LOCAT001 add constraint PK_LOCATION_ID primary key("LOCATION_ID") ; CREATE TABLE LOCAT002 AS (SELECT LOCATION_ID, STREET_ADDRESS, STATE_PROVINCE FROM LOCATIONS ); alter table LOCAT002 add constraint PK_LOCATION02_ID primary key("LOCATION_ID") ; UPDATE LOCAT002 SET STATE_PROVINCE=NULL; UPDATE LOCAT002 SET STATE_PROVINCE=NULL / COMMIT /

The source table.



The target table.




--2--Do the update now with the select.




--3-- See the result .