Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

Topic: SQL*Plus and PL/SQL >> Encounter a problem : SQL

Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property. You may review the entire Oracle Certification Program Candidate Agreement online Here.



  


 Title: Encounter a problem : SQL
 Vaibhav  Posted: Apr 22, 2008 02:05:43 AM

 Total Post: 11
 Joined: Jan, 2008






 Hello Dear,

I create a table-

create table emp(
name varchar2(10),
salary number(5))

insert into emp values('A',10000)
insert into emp values('B',9000)
insert into emp values('C',5000)

the result is
----------------
name salary
A 10000
B 9000
C 5000

Now I want to display the result as -

Name A B C
Salary 10000 9000 5000

Kindly help !!
Looking forward for your response.


 GOPU
Posted: Apr 22, 2008 02:46:33 AM  

 Total Post: 272
 Joined: Apr, 2008






 
HI,
it is possible butyou have to use some plsql methods to display like that.

regards
Gopu

 Vaibhav
Posted: Apr 22, 2008 04:09:35 AM  

 Total Post: 11
 Joined: Jan, 2008






 
Can Anyone tell me what Pl/Sql methods I have to use.

Thanks in advance !!

 Murtuja
Posted: Apr 22, 2008 04:27:47 AM  

 Total Post: 843
 Joined: Jan, 2006






 
Hi,

http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_code_a_matrix.2Fcrosstab.2Fpivot_report_in_SQL.3F

 gps
Posted: Apr 22, 2008 06:07:20 AM  

 Total Post: 38
 Joined: May, 2006






 
Try this PL/SQL Code for desired result:

set serveroutput on
declare
cursor c1 is select name, sal from emp
order by name;
one varchar2(4000):='Name ';
two varchar2(4000):='Salary ';
begin
for i in c1 loop
one:=one||' '||i.name;
two:=two||' '||i.sal;
end loop;

dbms_output.put_line(one);
dbms_output.put_line(two);
end;
/



Gurwinder

 GOPU
Posted: Apr 22, 2008 06:24:03 AM  

 Total Post: 272
 Joined: Apr, 2008






 
Hi,

Very good answer man... :).
I run that query and i got the answer...

thanks for sharing that
Gopu

SQL> declare
2 cursor c1 is select name, salary from emp order by name;
3 one varchar2(4000):='Name ';
4 two varchar2(4000):='Salary ';
5 begin
6 for i in c1 loop
7 one:=one||' '||i.name;
8 two:=two||' '||i.salary;
9 end loop;
10 dbms_output.put_line(one);
11 dbms_output.put_line(two);
12 end;
13 /
Name A B C
Salary 10000 9000 5000

PL/SQL procedure successfully completed.


 Vaibhav
Posted: Apr 22, 2008 11:12:10 PM  

 Total Post: 11
 Joined: Jan, 2008






 
thanks !! it works

 Time Zone: EDT

  




Forum Rules & Description


Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user




 








Get FREE Magazines

Top 10 Forum User

  Murtuja Khokhar843
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Gitesh Trivedi322
  Gopu Gopi272
  neeraj sharma252
  Ramesh Jois245
  Bishal Khetan207






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software