Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Dynamic Order By with Union

Dynamic Order By with Union

From: Joseph Miller <joseph_m_miller_at_yahoo.com>
Date: 13 Aug 2002 09:13:48 -0700
Message-ID: <e1cdca5e.0208130813.7120a75d@posting.google.com>


I'm having trouble using a DECODE statement in the ORDER BY clause with a UNION ALL in PL/SQL. Here's a simple example:

This works:

SELECT InvoiceNumber
FROM Invoice
WHERE BuyerName = 'x'
ORDER BY DECODE(inOrderByVariable, 'invoiceNumber', 1);

And this works:

SELECT InvoiceNumber
FROM Invoice
WHERE BuyerName = 'x'
UNION ALL
SELECT InvoiceNumber
FROM Invoice
WHERE SellerName = 'y'
ORDER BY 1; But this doesn't work:

SELECT InvoiceNumber
FROM Invoice
WHERE BuyerName = 'x'
UNION ALL
SELECT InvoiceNumber
FROM Invoice
WHERE SellerName = 'y'
ORDER BY DECODE(inOrderByVariable, 'invoiceNumber', 1);

any ideas? thanks. Joe Received on Tue Aug 13 2002 - 11:13:48 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US