Felipe Vidal
Felipe Vidal

Reputation: 505

Oracle SQL - Define table names for later usage?

I wanted to know if there is a way, in SQL Oracle, to do some range-definition (like in Excel). For example:

DEFINE TABLE1 = SELECT FIELD1, FIELD2, FIELD3 FROM [SCHEMA].[TABLE0][WHERE/GROUP BY/HAVING/ORDER BY/...];

DEFINE TABLE2 = SELECT FIELD1, FIELD2, FIELD3 FROM TABLE1 [WHERE/GROUP BY/HAVING/ORDER BY/...];

DEFINE TABLE3 = SELECT FIELD1, FIELD2, FIELD3 FROM TABLE2 LEFT JOIN TABLE1 ON [CONDITIONS];

SELECT * FROM TABLE3;

Thanks a lot in advance.

Upvotes: 0

Views: 268

Answers (2)

Felipe Vidal
Felipe Vidal

Reputation: 505

TO close this question. From one of the comments (Steve), what I needed is a WITH clause, as I didn't have DDL privileges.

Thanks,

Upvotes: 0

sstan
sstan

Reputation: 36543

Based on your examples, it sounds like you want to create views:

CREATE VIEW TABLE1 AS
SELECT FIELD1, FIELD2, FIELD3
FROM [SCHEMA].[TABLE0][WHERE/GROUP BY/HAVING/...];

CREATE VIEW TABLE2 AS
SELECT FIELD1, FIELD2, FIELD3
FROM TABLE1 [WHERE/GROUP BY/HAVING/...];

CREATE VIEW TABLE3 AS
SELECT FIELD1, FIELD2, FIELD3
FROM TABLE2
LEFT JOIN TABLE1 ON [CONDITIONS];

SELECT * FROM TABLE3;

Upvotes: 3

Related Questions