RE: Select Query - Help required

2002-07-31 Thread Aponte, Tony
Title: RE: Select Query - Help required






I posted an answer on a similar question about 2 weeks ago.  The underlying concept is how to pivot a result set.  I've attached the thread below.

HTH

Tony Aponte

Home Shopping Network




-Original Message-

From: Aponte, Tony 

Sent: Tuesday, July 23, 2002 10:38 AM

To: Multiple recipients of list ORACLE-L

Subject: RE: SQL Query



I hope this is not to late for you.  Anyway, this questions comes up often.  Below is the solution to pivot rows for up to 12 values of field1.  Just adjust to fit your range of values.

HTH 

Tony Aponte 

Home Shopping Network, Inc. 


create table tab1 (field1 number,field2 varchar2(30)); 

insert into tab1 values( 1,'RAM'); 

insert into tab1 values( 1,'SHAM'); 

insert into tab1 values( 1,'PAT'); 

insert into tab1 values( 2,'MAN'); 

insert into tab1 values( 2,'JOHN'); 

commit; 


SELECT 

g1 

,MAX(DECODE(line_no,01,value,NULL)) || 

MAX(DECODE(line_no,02,value,NULL)) || 

MAX(DECODE(line_no,03,value,NULL)) || 

MAX(DECODE(line_no,04,value,NULL)) || 

MAX(DECODE(line_no,05,value,NULL)) || 

MAX(DECODE(line_no,06,value,NULL)) || 

MAX(DECODE(line_no,07,value,NULL)) || 

MAX(DECODE(line_no,08,value,NULL)) || 

MAX(DECODE(line_no,09,value,NULL)) || 

MAX(DECODE(line_no,10,value,NULL)) || 

MAX(DECODE(line_no,11,value,NULL)) || 

MAX(DECODE(line_no,12,value,NULL)) 

FROM (SELECT g1,value,row_number() over(partition by g1 order by g1 nulls last) line_no 

FROM (SELECT field1 g1,field2 value from tab1) 

) 

GROUP BY g1; 




G1  MAX(DECODE(LINE_NO,01,VALUE,NU 

1   RAMSHAMPAT 

2   MANJOHN 


-Original Message- 

From: Ramasubramanian, Shankar (Cognizant) 

[mailto:[EMAIL PROTECTED]] 

Sent: Thursday, July 18, 2002 4:35 PM 

To: Multiple recipients of list ORACLE-L 

Subject: SQL Query 




Hi Friends, 

    I just need a help in a sql . I am having rows in a table as follows 


Field1(ID)    Field2(NAME) 

-- 

1 RAM 

1 SHAM 

1 PAT 

2 MAN 

2 JOHN 


Now i want the output to be as follows 


FIELD1  FIELD2 

-- 

1   RAMSHAMPAT 

2   MANJOHN 


In the output i have to show all the names for the same id in a single row. 

Please help me in getting this output using a SQL query  and not through 

cursors. 


Thanks in advance. 


Regards, 

Shankar 




-Original Message-

From: karthikeyan S [mailto:[EMAIL PROTECTED]]

Sent: Monday, July 29, 2002 10:08 AM

To: Multiple recipients of list ORACLE-L

Subject: Select Query - Help required



Gurus,


Please read the following problem and help me if you have any solution. 


Select product_id from  where id = 2; 


Product_ID

--

A

B

C

D


But I want the output as follows: 


Select product_id from  where id = 2; 


Product ID

-

ABCD.


Thanks in advance. 


regards,

Karthik 


-- 

Please see the official ORACLE-L FAQ: http://www.orafaq.com

-- 

Author: karthikeyan S

  INET: [EMAIL PROTECTED]


Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051

San Diego, California    -- Public Internet access / Mailing Lists



To REMOVE yourself from this mailing list, send an E-Mail message

to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in

the message BODY, include a line containing: UNSUB ORACLE-L

(or the name of mailing list you want to be removed from).  You may

also send the HELP command for other information (like subscribing).





RE: Select Query - Help required

2002-07-30 Thread Amjad Saiyed

u can write a cursor.
or u want the o/p in 1 select statement

rgds,
Ams.
www.medicomsoft.com

|-Original Message-
|From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of 
|karthikeyan
|S
|Sent: Monday, July 29, 2002 6:08 PM
|To: Multiple recipients of list ORACLE-L
|Subject: Select Query - Help required
|
|
|Gurus,
|
|Please read the following problem and help me if you have any 
|solution. 
|
|Select product_id from  where id = 2; 
|
|Product_ID
|--
|A
|B
|C
|D
|
|But I want the output as follows: 
|
|Select product_id from  where id = 2; 
|
|Product ID
|-
|ABCD.
|
|Thanks in advance. 
|
|regards,
|Karthik 
|
|-- 
|Please see the official ORACLE-L FAQ: http://www.orafaq.com
|-- 
|Author: karthikeyan S
|  INET: [EMAIL PROTECTED]
|
|Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
|San Diego, California-- Public Internet access / Mailing Lists
|
|To REMOVE yourself from this mailing list, send an E-Mail message
|to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
|the message BODY, include a line containing: UNSUB ORACLE-L
|(or the name of mailing list you want to be removed from).  You may
|also send the HELP command for other information (like subscribing).
|
|

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Amjad Saiyed
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



RE: Select Query - Help required

2002-07-29 Thread John . Hallas

A similar question was asked a while ago and I kept the answer as I thought
it might be useful
The following PL/SQL snippet should demonstrate a way to do what you want
 
set serveroutput on 100
Declare
  sn varchar2(2000);
  cursor c_devices is
select name from ashoke;
Begin
  for v_devices in c_devices loop
exit when c_devices%notfound;
sn := sn || ',' || v_devices.name;
  end loop;
  dbms_output.put_line(sn);
End;
/

John



-Original Message-
Sent: 29 July 2002 15:08
To: Multiple recipients of list ORACLE-L


Gurus,

Please read the following problem and help me if you have any solution. 

Select product_id from  where id = 2; 

Product_ID
--
A
B
C
D

But I want the output as follows: 

Select product_id from  where id = 2; 

Product ID
-
ABCD.

Thanks in advance. 

regards,
Karthik 

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: karthikeyan S
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: 
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).