dbTalk Databases Forums  

Rows into Columns, Datagrid preparation without Dynamic SQL

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Rows into Columns, Datagrid preparation without Dynamic SQL in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sumit
 
Posts: n/a

Default Rows into Columns, Datagrid preparation without Dynamic SQL - 03-18-2009 , 02:27 AM






Hi All,

Can someone help me with this issue?

We have three tables with the following structure.

SELECT * FROM market;

comp_no comp_name
100 ABC
101 DEF
102 AcME
103 XYZ
.. .
.. .
.. .
.. .
.. .

SELECT * FROM products;

pdt_no pdt_name
200 Paper
201 Staples
202 Pencil
203 Eraser
.. .
.. .
.. .
.. .
.. .
.. .


SELECT * FROM sale_data;

comp_no pdt_no sell_amt
100 200 10000
100 201 20000
100 202 30000
101 203 15000
103 200 99999
103 202 50000

I need the sale_data as a grid, with the product making the columns
and markets making the rows.

comp_no 200 201 202 203 . . . .
100 10000 20000 30000 <NULL>
101 <NULL> <NULL> <NULL> 15000
102 <NULL> <NULL> <NULL> <NULL>
103 99999 <NULL> 50000 <NULL>
.. . . . .
.. . . . .
.. . . . .
.. . . . .
.. . . . .

I know that we can do this using dynamic sql, but we have a number of
prducts in the product and it causes buffer overflow error with the
query. Highly appreciated if someone can provide any workaround or
approach to attack this problem..

Thanks

Sumith

Reply With Quote
  #2  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Rows into Columns, Datagrid preparation without Dynamic SQL - 03-18-2009 , 07:53 AM






On Mar 18, 4:27*am, sumit <sumithcn... (AT) gmail (DOT) com> wrote:
Quote:
Hi All,

Can someone help me with this issue?

We have three tables with the following structure.

SELECT * FROM market;

comp_no comp_name
100 * * ABC
101 * * DEF
102 * * AcME
103 * * XYZ
. * * * .
. * * * .
. * * * .
. * * * .
. * * * .

SELECT * FROM products;

pdt_no *pdt_name
200 * * Paper
201 * * Staples
202 * * Pencil
203 * * Eraser
. * * * .
. * * * .
. * * * .
. * * * .
. * * * .
. * * * .

SELECT * FROM sale_data;

comp_no pdt_no *sell_amt
100 * * 200 * * 10000
100 * * 201 * * 20000
100 * * 202 * * 30000
101 * * 203 * * 15000
103 * * 200 * * 99999
103 * * 202 * * 50000

I need the sale_data as a grid, with the product making the columns
and markets making the rows.

comp_no 200 * * 201 * * 202 * * 203 * * . * * * . * * * . * * * .
100 * * 10000 * 20000 * 30000 * <NULL
101 * * <NULL> * *<NULL> * *<NULL> * *15000
102 * * <NULL> * *<NULL> * *<NULL> * *<NULL
103 * * 99999 * <NULL> * *50000 * <NULL
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .

I know that we can do this using dynamic sql, but we have a number of
prducts in the product and it causes buffer overflow error with the
query. Highly appreciated if someone can provide any workaround or
approach to attack this problem..

Thanks

Sumith
Try searching the archives on pivot table.
What version of Oracle? This looks like something that could be done
using the model statement of 10g and probably can also be done using
analytic queries 8.1.6+.

HTH -- Mark D Powell --



Reply With Quote
  #3  
Old   
William Robertson
 
Posts: n/a

Default Re: Rows into Columns, Datagrid preparation without Dynamic SQL - 03-19-2009 , 01:41 AM



On Mar 18, 8:27*am, sumit <sumithcn... (AT) gmail (DOT) com> wrote:
Quote:
Hi All,

Can someone help me with this issue?

We have three tables with the following structure.

SELECT * FROM market;

comp_no comp_name
100 * * ABC
101 * * DEF
102 * * AcME
103 * * XYZ
. * * * .
. * * * .
. * * * .
. * * * .
. * * * .

SELECT * FROM products;

pdt_no *pdt_name
200 * * Paper
201 * * Staples
202 * * Pencil
203 * * Eraser
. * * * .
. * * * .
. * * * .
. * * * .
. * * * .
. * * * .

SELECT * FROM sale_data;

comp_no pdt_no *sell_amt
100 * * 200 * * 10000
100 * * 201 * * 20000
100 * * 202 * * 30000
101 * * 203 * * 15000
103 * * 200 * * 99999
103 * * 202 * * 50000

I need the sale_data as a grid, with the product making the columns
and markets making the rows.

comp_no 200 * * 201 * * 202 * * 203 * * . * * * . * * * . * * * .
100 * * 10000 * 20000 * 30000 * <NULL
101 * * <NULL> * *<NULL> * *<NULL> * *15000
102 * * <NULL> * *<NULL> * *<NULL> * *<NULL
103 * * 99999 * <NULL> * *50000 * <NULL
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .
. * * * . * * * . * * * . * * * .

I know that we can do this using dynamic sql, but we have a number of
prducts in the product and it causes buffer overflow error with the
query. Highly appreciated if someone can provide any workaround or
approach to attack this problem..

Thanks

Sumith
If the columns are not known until you've read the rows,a dynamic
solution is going to be necessary.

What buffer overflow error do you get? Are you using DBMS_OUTPUT for
reporting? A dynamic ref cursor would be a better approach.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.