I have three columns (NUM1, NUM2, NUM3) of "number" datatype in table 1, and while inserting to table2 using "insert into table2 select * from table1", I want to insert the three columns into one column(NUM).
I'm using Oracle 8i, and only one of the three columns will have a value in a row, while others will have null values.
I understand from your question that only one and exactly one number from the three numbers will be filled, and the others will stay null. If this is the case, do a:
Insert into table2 (f1,f2,........fk) select v1, v2, .....vk from table1;where table2 has the num field. Insert a corresponding DECODE expression that does the following:
DECODE ( NVL (NUM1 ,3) / NVL(NUM1,1) *100 + NVL(NUM2,5) / NVL(NUM2,1) *10+ NVL(NUM3,7)/ NVL(NUM3,1) , 157,NUM1,317,NUM2,351,NUM3)This expression is designed to identify which column to return.
For More Information
- Dozens more answers to tough Oracle questions from Eli Leiba are available here.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle and SQL
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.