I 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_
hdr_id%TYP
E,
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
ame = 'Approved'
-- 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;