Oracle: How to reference an alias with a space from a subquery in a comparison operation
Yes, you can do this, but you have to enclose those names in double quotes:
-- SQL ExampleSELECT "Just one" FROM ( SELECT 1 AS "Just one" FROM dual);
Output:
Just one---------- 1
-- PL/SQL ExampleBEGIN FOR v_rec IN (SELECT 1 AS "Just one" FROM dual) LOOP dbms_output.put_line(v_rec."Just one"); END LOOP;END;/
Output:
1
And a little curiosity:
BEGIN FOR v_rec IN (SELECT COUNT(1) * 10 FROM dual) LOOP dbms_output.put_line(v_rec."COUNT(1)*10"); END LOOP;END;
This works.. and prints:
10
Edit
You can reference the aliased column elsewhere in your query, for example:
SELECT 'It is just one' FROM ( SELECT "Just one" FROM ( SELECT 1 AS "Just one" FROM dual ) tWHERE t."Just one" = 1 -- prefixing with t. is not necessary in this particular example);
Output:
It is just one