Application of the update statement in Oracle multi-Table Association

Source: Internet
Author: User

The following article describes the actual application of the update statement in Oracle multi-Table Association, we have established the following simple model and constructed part of the test data: in a business acceptance subsystem BSS,

Customer Data Table

 
 
  1. create table customers  
  2. (  
  3. customer_id number(8) not null,   

Customer ID

 
 
  1. city_name varchar2(10) not null, 

City

 
 
  1. customer_type char(2) not null, 

Customer type

 
 
  1. ...  
  2. )  
  3. create unique index PK_customers on customers (customer_id)  

For some reason, the customer's city information is not accurate,

In the CRM subsystem of the customer service department, 20% of the customers are obtained through the active service

City and other accurate information, so you extract this part of information to a temporary table:

 
 
  1. create table tmp_cust_city  
  2. (  
  3. customer_id number(8) not null,  
  4. citye_name varchar2(10) not null,  
  5. customer_type char(2) not null  
  6. )  

1) The simplest form

It is confirmed that all mermer_id less than 1000 in the MERs table are 'beijing'

Less than 1000 of the customers are old customers in the city before the company moved to the country :)

 
 
  1. update customers 

Set city_name = 'beijing'

 
 
  1. where customer_id<1000 

2) two tables (multiple tables) join Oracle update only in the where clause

The extracted data is VIP and includes new ones. Therefore, the customer category is updated by the way.

 
 
  1. update customers a  

Use alias

 
 
  1. set customer_type='01'  

01 is vip, 00 is normal

 
 
  1. where exists (select 1  
  2. from tmp_cust_city b  
  3. where b.customer_id=a.customer_id  
  4. )  

3) The modified values of Oracle two-table (Multi-table) associated update are calculated from the other table.

 
 
  1. update customers a  

Use alias

 
 
  1. set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)  
  2. where exists (select 1  
  3. from tmp_cust_city b  
  4. where b.customer_id=a.customer_id  
  5. )   

The above content is the description of the update statement associated with Oracle multi-table, hoping to help you in this regard.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.