The following SQL is trying to select some values, where it satisfies the condition that
select cd as key_type, decode
from general_code
where key_type = 'A_MAP_TYPE'
and cd in (
select distinct(A_MAP_TYPE)
from sales_channel
);
A_MAP_TYPE is a column name (and FK) in table sales_channel, and it is being referenced in general_code (as PK).
I realize that this SQL is non portable in that when the name of A_MAP_TYPE changes, i.e. to B_MAP_TYPE, then the corresponding SQL needs to be changed. Is there a way to do something like PL/SQL‘s TABLE_NAME.COLUMN_NAME%TYPE in this SQL?
You could use dynamic SQL. It would probably require some changes to the way your query is setup now, but should be doable.
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/dynamic.htm
You basically would need to turn your current query into a string, and execute the string. Where your current A_Map_ field is, that would be a parameter. For the first case you would need to quote it so that it’s still a string within the executing string. For the second A_Map_ field, you would put quotes around it,