Oracle is case-sensitive, however, the default behaviour is for Oracle to hide its case-sensitivity by converting all unquoted identifiers to upper case and it is only quoted identifiers where the case remains unchanged. So, in the inner query you have "Last_Time"
which is quoted so Oracle will respect the case of the identifier, whereas the outer query uses Last_Time
which is unquoted and oracle will convert it to LAST_TIME
and this does not exist in the inner query.
You can either remove the quotation marks from the inner query:
SELECT a.*,
CASE
WHEN a.Last_Time > '06:00' AND a.Last_Time < '09:00' THEN '1'
WHEN a.Last_Time > '09:00' AND a.Last_Time < '12:00' THEN '2'
WHEN a.Last_Time > '12:00' AND a.Last_Time < '15:00' THEN '3'
WHEN a.Last_Time > '15:00' AND a.Last_Time < '18:00' THEN '4'
ELSE '5'
END AS L_T
FROM (
SELECT substr(LAST_LOCATED_TIME,12,5) as Last_Time
FROM GPS_REPORT_DAILY
)a;
Or use quotation marks for all the identifiers in the outer query:
SELECT a.*,
CASE
WHEN a."Last_Time" > '06:00' AND a."Last_Time" < '09:00' THEN '1'
WHEN a."Last_Time" > '09:00' AND a."Last_Time" < '12:00' THEN '2'
WHEN a."Last_Time" > '12:00' AND a."Last_Time" < '15:00' THEN '3'
WHEN a."Last_Time" > '15:00' AND a."Last_Time" < '18:00' THEN '4'
ELSE '5'
END AS L_T
FROM (
SELECT substr(LAST_LOCATED_TIME,12,5) as "Last_Time"
FROM GPS_REPORT_DAILY
)a;
Or, use upper-case in the quoted identifier:
SELECT a.*,
CASE
WHEN a.Last_Time > '06:00' AND a.Last_Time < '09:00' THEN '1'
WHEN a.Last_Time > '09:00' AND a.Last_Time < '12:00' THEN '2'
WHEN a.Last_Time > '12:00' AND a.Last_Time < '15:00' THEN '3'
WHEN a.Last_Time > '15:00' AND a.Last_Time < '18:00' THEN '4'
ELSE '5'
END AS L_T
FROM (
SELECT substr(LAST_LOCATED_TIME,12,5) as "LAST_TIME"
FROM GPS_REPORT_DAILY
)a;
(Also note that you are using non-inclusive ranges lower_bound < value < upper_bound
so if the time is exactly 09:00
then it does not fall into either of the 1
or 2
cases.)