Solved

How To Do Conditional Insert in Oracle?

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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 video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

705 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