astrak
astrak

Reputation: 205

Identifier for a long function in SELECT

I use PL/SQL developer and I wrote long "equation" in SELECT, where are also use functions. This equation I also need to use in another part of my script. It looks like

SELECT t.something1,
       ROUND((SYSDATE - 1 + 2),1) AS NAME
FROM customers t
WHERE t.something1 = ROUND((SYSDATE - 1 + 2),1)

My question is: is it possible to make something like identifier for ROUND((SYSDATE - 1 + 2),1) to avoid using this long line also in WHERE?

Thank you very much.

Upvotes: 0

Views: 46

Answers (1)

Frank Schmitt
Frank Schmitt

Reputation: 30845

Just split it into two SELECTs:

select v1.* from (
  SELECT 
    t.something1,
    ROUND((SYSDATE - 1 + 2),1) AS NAME
  FROM customers t
) v1
WHERE v1.something1 = v1.name

Upvotes: 2

Related Questions