Solved

How To Do Conditional Insert in Oracle?

Posted on 2014-11-20
1
316 Views
Last Modified: 2014-11-20
Dear Experts,

I have two tables with names  TA and TB. TA has columns a,b,c,d and TB has columns x,y,z,t. I'm going to insert columns x, y, z from TB into TA. However, the remaining column in TA, the column d, will be zero if value of the column t in TB is 'AD'  otherwise it will be one.  

In other words, something like this:

insert into TA (a,b,c,d) select x,y,z,(0 if t='AD' otherwise '1') from TB;

Could you help me?

BR
0
Comment
Question by:GurcanK
1 Comment
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40455082
insert into TA (a,b,c,d) select x,y,z,(case when t='AD' then 0 else 1 end) from TB;
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
use lov values 2 61
How to Comment Out Lines of Code in a Pass Through Query In MS Access 2016 19 64
Oracle DBLINKS From 11g to 8i 3 47
Fill Null values 5 28
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question