Hi I need help to understand the decode part of a query that goes something like the following.
SELECT ax.animal_code
FROM raw_animal_xref ax,
animal_xref_type axt
WHERE ax.animal_mnemonic = l_animal_mnemonic -- Example 'COUGAR'
AND ax.animal_code_type = axt.animal_code_type
ORDER BY DECODE (animal_type,
l_type_to_be_matched, -1, -- Example 'CATS'
l_current_type, 0, -- Example 'BIG CATS'
nvl(axt.type_search_priority, 100)) ASC; -- EXAMPLE 'Big Cats' Priority is 1
Since this query returns only 1 query, I'm a little stumped on how the ORDER BY works with the different non-existing column numbers supplied by DECODE. The query works as a cursor to find a unique code for the animal in question given a animal mnemonic the current animal type and the type to be matched with.
I'm thinking that DECODE returns the different column numbers to ORDER BY with and I tried experimenting with a different simple single column selects on some other tables with ORDER by '-1', '0' and '100' and the ORDER by seems to fail for 0 and 100. Why does it work with -1 or any of the other numbers?
Hope someone can explain this to me. Thanks!