I need to write a script to insert data selected from one table into another. The old table stores a value ‘Yes’ in one column but I want to insert 1 instead of ‘Yes’
Is there any way to do this. In my head this is what I want to do:
insert into new_table (new_col1, new_col2)
values (select from old_table(old_col1, (if old_col2='Yes' then 1 else 0))
First: if you base your insert on a SELECT, the must not use the
VALUESclause.To get a conditional value, use the (ANSI standard) CASE statement:
An Oracle only more compact form would be the decode() statement (but I’d recommend to use the CASE, because it’s more readable and portable to other DBMS as well)