If I sort it in asc in excel it is ok.
What is wrong. Pool Code is 02 a
and then the GRADE is the grade name.
No.1 Canada Western Amber Durum Ac
Main Topics
Browse All TopicsI have the following query that is not sort properly.
No.1 Canada Western Amber Durum Ac
should come after
No.1 Canada Western Amber Durum Ac Strongfield
Please see attached file.
Why does the following oracle statement does not order it properly.
PROCEDURE get_Grades (cur_out IN OUT t_cursor,
p_price_list_hdr_id IN price_list_dtl.price_list_
p_status OUT NOCOPY varchar2)
-- for the Grade Codes spreadsheet
IS
BEGIN
p_status := 'Success';
OPEN cur_out
FOR
-- ALL 4 GRAINS
SELECT C.grade_pool_code, C.grain_class_name, C.grade_protein_pct, B.strght_price_amt - A.old_price_amt delta_price,
D.strght_code, B.strght_price_amt, D.tough_code, D.damp_code, D.stone_code, D.tough_stone_code, D.damp_stone_code, G.sct_effctv_dtm,
G.pool_part_code
FROM (select E.grade_code_dtl_id, max(e.strght_price_amt) old_price_amt
FROM price_list_dtl E, price_list_hdr F
WHERE F.price_list_hdr_id = F.price_list_hdr_id
-- AND F.price_list_status_type_n
-- AND F.load_type_name in ('Initial','Adjustment')
-- and e.price_list_hdr_id < p_price_list_hdr_id
and e.price_list_hdr_id = p_price_list_hdr_id
GROUP BY e.grade_code_dtl_id) A, price_list_dtl B, grade_code_dtl C, price_list_hdr G,
(Select grade_code_dtl_id,
max(CASE code_type_name when 'STRAIGHT' then disc_code else null end) as Strght_Code,
max(CASE code_type_name when 'TOUGH' then disc_code else null end) as Tough_Code,
max(CASE code_type_name when 'DAMP' then disc_code else null end) as Damp_Code,
max(CASE code_type_name when 'STONE' then disc_code else null end) as Stone_Code,
max(CASE code_type_name when 'TOUGH STONE' then disc_code else null end) as Tough_Stone_Code,
max(CASE code_type_name when 'DAMP STONE' then disc_code else null end) as Damp_Stone_Code
from grade_item
group by grade_code_dtl_id) D
WHERE B.price_list_hdr_id = p_price_list_hdr_id
AND C.grade_code_dtl_id = B.grade_code_dtl_id
AND A.grade_code_dtl_id = C.grade_code_dtl_id
AND D.grade_code_dtl_id = C.grade_code_dtl_id
AND G.price_list_hdr_id = b.price_list_hdr_id
ORDER BY grade_pool_code,grade_name
EXCEPTION
WHEN OTHERS THEN
p_status := 'Failure: ' || SQLERRM;
END get_Grades;
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Nulls will sort last, if you want the nulls to sort first, substitute a low character value in place of the null. the two examples below will demonstrate.
SELECT grade_pool_code, grade_name
FROM (SELECT 'No.1 Canada Western Amber Durum' grade_pool_code
, 'Strongfield' grade_name
FROM DUAL
UNION ALL
SELECT 'No.1 Canada Western Amber Durum' grade_pool_code, '' grade_name
FROM DUAL)
order by grade_pool_code, grade_name;
SELECT grade_pool_code, grade_name
FROM (SELECT 'No.1 Canada Western Amber Durum' grade_pool_code
, 'Strongfield' grade_name
FROM DUAL
UNION ALL
SELECT 'No.1 Canada Western Amber Durum' grade_pool_code, '' grade_name
FROM DUAL)
order by grade_pool_code, nvl(grade_name,chr(30));
if you're looking for a sorting rule that will identify an arbitrary string and put it in a special place different from the rest of the sorting rules, you'll need to provide some way to identify that arbitrary string.
so, if you want 'No.1 Canada Western Amber Durum Ac' to have a special location independent of the alphabetical sorting of the rest of column then you'll have to search for that one string and give it a rule. Something like this...
mathieu_cupryk,
Trying to get the experts here to understand the full scope of your setup can be problematic at times. I think this is one of those times.
I find that creating as simplified test case as possible works best. I suggest you post a small test case that includes: table definition, sample data and expected results.
For example:
Given the following script I need code 2 to come after code 1 because <insert reason here>.
the problem here is capturing the difference between what the query is returning and what shows up on the spreadsheet. The columns have different names so, it appears the sorting is happening by something other than what appears in column "A" of the spreadsheet.
I think from the last post, the jpeg, assuming that is a direct dump of what I hoped would come from sqlplus, then yes, it looks like the sorting column is grain_class_name
not grade_name
you should be able to download and install the SQL*Plus instant client from otn.
No Cost. (http://www.oracle.com/tec
and you shouldn't need to be an admin to install it.
it's one flavor of the instant client
http://www.oracle.com/tech
or better yet here, you can see all the different variations of the instant client
http://www.oracle.com/tech
Business Accounts
Answer for Membership
by: sdstuberPosted on 2008-08-25 at 11:49:04ID: 22308014
why would
No.1 Canada Western Amber Durum Ac
come after
No.1 Canada Western Amber Durum Ac Strongfield
alphabetically it should come first, however, I'm not sure based on your spreadsheet columns and your query columns what your order by is supposed to be saying