How do I search for any string value from a column manipulated from the table in Oracle SQL

advertisements

How can I search any string value from a manipulated column of table like:

SELECT SUBSTR(DESCR,1,8) AS MYDES FROM STATION WHERE descr='ABERDEEN';

I want to search 'ABERDEEN' from SUBSTR(DESCR,1,8) or 'MYDES' column but in my case 'ABERDEEN' is still searched from DESCR column. How can I search it from the new manipulated 'MYDES' column (oracle, sql)?


If you want to filter the rows which has the substr as ABERDEEN in the column descr, then use the function in the filter predicate.

For example,

SELECT * FROM STATION WHERE SUBSTR(DESCR,1,8)='ABERDEEN';

To include the new column in the output along with other columns,

SELECT t.*,
  SUBSTR(DESCR,1,8) AS MYDES
FROM STATION
WHERE SUBSTR(DESCR,1,8)='ABERDEEN';