Solved

How To Do Conditional Insert in Oracle?

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

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need help with Oracle syntax 4 42
Oracle Database creation fails 5 37
PL/SQL Search for multiple strings 5 21
sql query 9 21
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

757 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

20 Experts available now in Live!

Get 1:1 Help Now