How to sort within concatenated columns [message #620365] |
Thu, 31 July 2014 14:04 |
rappaj
Messages: 147 Registered: June 2010 Location: NYC
|
Senior Member |
|
|
Hi all,
Hopefully someone can help me here...
The below SQL produces 1 long concatenated result, and when exported to EXCEL, it formats it there correctly. When the SQL reads from the database, the trim(plv.line_num) is read...10, 9, 8, 7, etc....
I would like to sort trim(plv.line_num) if possible to be 1, 2, 3, 4, etc....
By looking at the Sample incorrect Output below, would any of you know how I can get the sort working on the line number from the smallest to largest? I've tried a few different things, but no luck because of all the concatenated fields.
Thanks,
Joe
select 'Item Section' || chr(09) ||
'Action' || chr(09) ||
'Line Number' || chr(09) ||
'Line Type' || chr(09) ||
'Thumbnail Image' || chr(09) ||
'Image' || chr(09) ||
'Description' || chr(09)
from dual
UNION ALL
select
'' || chr(09) ||
'SYNC' || chr(09) ||
trim(plv.line_num) || chr(09) ||
'' || chr(09) ||
icav.thumbnail_image || chr(09) ||
icav.picture || chr(09) ||
'Item Image' || chr(09)
FROM apps.po_headers_v phv,
apps.po_lines_v plv,
APPS.mtl_categories_b_kfv mc,
icx.ICX_CAT_ATTRIBUTE_VALUES icav
WHERE plv.po_header_id = phv.po_header_id
and mc.category_id = plv.category_id
and icav.po_line_id(+) = plv.po_line_id
and phv.segment1 = '1328700';
Sample Incorrect Output with Line Number sorted incorrectly:
'ITEMSECTION'||CHR(09)||'ACTION'||CHR(09)||'LINENUMBER'||CHR(09)||'LINETYPE'||CHR(09)||'THUMBNAILIMAGE'||CHR(09)||'IMAGE'||CHR(09)||'DESCRIPTION'||CHR(09)
Item Section Action Line Number Line Type Thumbnail Image Image Description
SYNC 10 Item Image
SYNC 9 Item Image
SYNC 8 Item Image
SYNC 7 Item Image
SYNC 6 Item Image
SYNC 5 Item Image
SYNC 4 Item Image
SYNC 3 Item Image
SYNC 2 Item Image
SYNC 1 Item Image
Desired Output with the sort working CORRECTLY:
'ITEMSECTION'||CHR(09)||'ACTION'||CHR(09)||'LINENUMBER'||CHR(09)||'LINETYPE'||CHR(09)||'THUMBNAILIMAGE'||CHR(09)||'IMAGE'||CHR(09)||'DESCRIPTION'||CHR(09)
Item Section Action Line Number Line Type Thumbnail Image Image Description
SYNC 1 Item Image
SYNC 2 Item Image
SYNC 3 Item Image
SYNC 4 Item Image
SYNC 5 Item Image
SYNC 6 Item Image
SYNC 7 Item Image
SYNC 8 Item Image
SYNC 9 Item Image
SYNC 10 Item Image
|
|
|
|
Re: How to sort within concatenated columns [message #620368 is a reply to message #620366] |
Thu, 31 July 2014 14:31 |
rappaj
Messages: 147 Registered: June 2010 Location: NYC
|
Senior Member |
|
|
Littlefoot.... Yes, that was one of the things I tried as well and got this error:
ORA-01785: ORDER BY item must be the number of a SELECT-list expression
01785. 00000 - "ORDER BY item must be the number of a SELECT-list expression"
I also tried to do an order by, using the whole select clause. N/G.
|
|
|
|
|
|
|
Re: How to sort within concatenated columns [message #620380 is a reply to message #620379] |
Thu, 31 July 2014 15:29 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
You could have also done it like this
select 'Item Section' || chr(09) ||
'Action' || chr(09) ||
'Line Number' || chr(09) ||
'Line Type' || chr(09) ||
'Thumbnail Image' || chr(09) ||
'Image' || chr(09) ||
'Description' || chr(09) line
from dual
UNION ALL
select line
from
(select
'' || chr(09) ||
'SYNC' || chr(09) ||
trim(plv.line_num) || chr(09) ||
'' || chr(09) ||
icav.thumbnail_image || chr(09) ||
icav.picture || chr(09) ||
'Item Image' || chr(09) line
FROM apps.po_headers_v phv,
apps.po_lines_v plv,
APPS.mtl_categories_b_kfv mc,
icx.ICX_CAT_ATTRIBUTE_VALUES icav
WHERE plv.po_header_id = phv.po_header_id
and mc.category_id = plv.category_id
and icav.po_line_id(+) = plv.po_line_id
and phv.segment1 = '1328700'
order by to_number(trim(plv.line_num)));
|
|
|
|
|