Solved

How To Do Conditional Insert in Oracle?

Posted on 2014-11-20
1
309 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now