Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Constant in Query (using WITH clause)

IniyavanMar 11 2020 — edited Mar 11 2020

Hi friends,

I need to use a computed date value repeatedly in my query, which is quite large. Is it possible to use it through WITH clause without making JOIN.

Or, is there any other way to use a runtime computed value repeatedly in query? I cannot go for PL/SQL or bind variable. Only a single query to be used.

My DB version is Oracle 12.2.

--Normal working scenario

WITH

with_result AS

  (SELECT trunc(sysdate-365) AS val_from_with FROM dual)

SELECT e.ename,e.JOB

FROM emp e

INNER JOIN with_result w

ON (e.hiredate >= w.val_from_with);

--Is it possible to use it like this (without join)?

WITH

with_result AS

  (SELECT trunc(sysdate-365) AS val_from_with FROM dual)

SELECT e.ename,e.JOB

FROM emp e

where e.hiredate >= with_result.val_from_with;

This post has been answered by RogerT on Mar 11 2020
Jump to Answer
Comments
Post Details
Added on Mar 11 2020
18 comments
2,773 views