Solved

How To Do Conditional Insert in Oracle?

Posted on 2014-11-20
1
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 77

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

733 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