Jan 30, 2002 #1 Mel1 Technical User Apr 3, 2001 3 US We have a decode statement in the select clause where we are storing the value into a alias field name. Can you use this alias field name in the where clause of the PL/SQL query?
We have a decode statement in the select clause where we are storing the value into a alias field name. Can you use this alias field name in the where clause of the PL/SQL query?
Jan 30, 2002 #2 Dagon MIS Jan 30, 2002 2,301 GB I didn't understand that. You might need to give a clearer example of what you are trying to do. Upvote 0 Downvote
Jan 30, 2002 Thread starter #3 Mel1 Technical User Apr 3, 2001 3 US The decode statement is something like: select decode(value1<value2, "late", value1=<value2, "on time", "early" part_status We want to use the alias part_status in the where statement of the same select -- for example select decode(table1.field1<table1.field2, "late", table1.field1=table1.field2, "on time", "early" part_status where part_status = "late" We keep getting an error that part_status is an invalid column name. We wondered if you could do this. Upvote 0 Downvote
The decode statement is something like: select decode(value1<value2, "late", value1=<value2, "on time", "early" part_status We want to use the alias part_status in the where statement of the same select -- for example select decode(table1.field1<table1.field2, "late", table1.field1=table1.field2, "on time", "early" part_status where part_status = "late" We keep getting an error that part_status is an invalid column name. We wondered if you could do this.
Jan 30, 2002 #4 Dagon MIS Jan 30, 2002 2,301 GB No, I don't think you can. You would have to repeat the decode e.g. select decode(table1.field1<table1.field2, "late", table1.field1=table1.field2, "on time", "early" part_status where decode(table1.field1<table1.field2, "late", table1.field1=table1.field2, "on time", "early" = "late" But I'm not sure this would be very sensible anyway. It might be more efficient just to re-write the query as: select "late" part_status from ... where table1.field1<table1.field2 That way, if there is an good index on table1.field1 or table2.field2, there's a chance Oracle will use it. With the decode there is no chance. Upvote 0 Downvote
No, I don't think you can. You would have to repeat the decode e.g. select decode(table1.field1<table1.field2, "late", table1.field1=table1.field2, "on time", "early" part_status where decode(table1.field1<table1.field2, "late", table1.field1=table1.field2, "on time", "early" = "late" But I'm not sure this would be very sensible anyway. It might be more efficient just to re-write the query as: select "late" part_status from ... where table1.field1<table1.field2 That way, if there is an good index on table1.field1 or table2.field2, there's a chance Oracle will use it. With the decode there is no chance.