INTERVIEW QUESTIONS
DATABASE
SQL
DETAILS
Question: lets i have a table "bapi" having 6 field like this f1 f2 f3 f4 f5 f6 ... ... .. ... ... ... p r o m o d
i want to retrive all the data by using select statement and my output will be look like this: xyz ... p r o m o d
Answer: elect xyz from ( select xyz,ord from ( select 1 as ord,f1 xyz from bapi union all select 2 as ord, f2 xyz from bapi union all select 3 as ord, f3 xyz from bapi union all select 4 as ord, f4 xyz from bapi union all select 5 as ord, f5 xyz from bapi union all select 6 as ord, f6 xyz from bapi ) inqry --order by ord,xyz ) outqry order by xyz
|
Question:
lets i have a table "bapi" having 6 field like this f1 f2 f3 f4 f5 f6 ... ... .. ... ... ... p r o m o d
i want to retrive all the data by using select statement and my output will be look like this: xyz ... p r o m o d
Answer:
elect xyz from ( select xyz,ord from ( select 1 as ord,f1 xyz from bapi union all select 2 as ord, f2 xyz from bapi union all select 3 as ord, f3 xyz from bapi union all select 4 as ord, f4 xyz from bapi union all select 5 as ord, f5 xyz from bapi union all select 6 as ord, f6 xyz from bapi ) inqry --order by ord,xyz ) outqry order by xyz Source: CoolInterview.com
Answered by: Srikanth | Date: 10/25/2007
| Contact Srikanth
Try this ...Playing with the strings Select 'xyz' + char(10) + '---' + char(10) + f1 + char(10)+ f2 + char(10)+ f3 + char(10)+ f4 + char(10)+ f5 + char(10)+ f6 from bapi Source: CoolInterview.com
Answered by: Aashish Mangal | Date: 9/21/2008
| Contact Aashish Mangal
Oracle 11g comes with a new function PIVOT similar to that of the pivoting of SQL Server Database. Source: CoolInterview.com
Answered by: Sameer | Date: 12/1/2009
| Contact Sameer
I think this qury is simple.. select f1 as xyz from bapi union all select f2 as xyz from bapi union all select f3 as xyz from bapi union all select f4 as xyz from bapi union all select f5 as xyz from bapi union all select f6 as xyz from bapi Source: CoolInterview.com
Answered by: Jothi | Date: 2/12/2010
| Contact Jothi
Hey Guys, Try this..
select orders FROM (SELECT f1, f2, f3,f4,f5,f6 FROM bapi) p UNPIVOT (orders for f8 in (f1,f2,f3,f4,f5,f6) ) AS unpvt Source: CoolInterview.com
Answered by: Muthu kumar E | Date: 4/27/2010
| Contact Muthu kumar E
select decode(r,1,f1,2,f2,3,f3,4,f4,5,f5,6,f6) from bapi,(select rownum r from user_tab_columns where table_name = 'BAPI') Source: CoolInterview.com
Answered by: m_nasef | Date: 5/5/2010
| Contact m_nasef
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|