in oracle - i am trying to figure out how to define variables in a with statement.
when i define a variable as a number it works fine:
with a as(
select 100 as query_rows
from dual
)
,b as (
select * from table1 where rownum=query_rows
)
select * from b --working great
however,if i want to define a date as a variable,i keep getting an error:
with a as(
select DATE '2020-10-01' as query_date
from dual
)
,b as (
select * from table1 where table1.date=query_date
)
select * from b -- ORA-00904 : "query_date" is not a valid identifier
from oracle :ORA-00904
You tried to execute a SQL statement that included an invalid column name or the column name is missing. This commonly occurs when you reference an invalid alias in a SELECT statement.
so,why does the first query work and the second one doesn't?
afrom thewithclause - just the same as in your second example. Oracle won't know what that identifier means - it's not about data types. So: did that first query really work for you, exactly as written? Really?