OracleSQL get substring of variable as new variable

Viewed 28

I have a column and I would like to get a new column using only the first two characters. I would have assumed the following should work, but it throws FROM keyword not found where expected error

SELECT *,
       SUBSTR(PHONE_NUMBER , 1,2) AS MY_PHONE_NUMBER
FROM PHONE_NOS;

Try it here

1 Answers

Alias the table and use it in the statement:

SELECT p.*,
       SUBSTR(p.PHONE_NUMBER, 1, 2) AS MY_PHONE_NUMBER
FROM PHONE_NOS p;
Related