SQL Language (MOSC)

MOSC Banner

How to condition the values for INSERT INTO table2 SELECT FROM table1?

edited Oct 8, 2013 4:45AM in SQL Language (MOSC) 5 commentsAnswered ✓
Hi all,
Values in col1 table1 = '0', '1'.
Values in col2 table2 = 'N', 'Y'.
Both column types = CHARACTER (1)

I need to insert into table2 col2 the values of table1 col1 where the value will be mapped from '0' to 'N' and '1' to 'Y'.

This is my current solution:

INSERT INTO table2 (col2)
SELECT col1
FROM table1;

Then, do the update accordingly:
UPDATE table2 set col2 = 'N' where col2 = '0';
UPDATE table2 set col2 = 'Y' where col2 = '1';

I am looking for some condition check, such as '0'?'N':'Y', without writing Stored Procedure. Is there a better way doing this.

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center