Select without a FROM clause in Oracle
To fetch data without a table in Oracle, use dual
, the system-owned, single-row table:
Generate a series without referencing a physical table, employ CONNECT BY
:
This gives you a sequence from 1 to 6 using just dual
and CONNECT BY
. Just don't bet your house on it!
The who and why of DUAL: fastest way to fetch data in Oracle without needing a table:
Generate a series without involving tables, by employing CONNECT BY
:
The level
pseudocolumn cooperates with dual
and CONNECT BY
to generate a count from 1-6.
The ABC and XYZ of DUAL
DUAL is a single-row, single-column table created during Oracle installation. All Oracle users have access to DUAL, a table that comes in handy when you need to fetch data without accessing a physical table.
Applications of DUAL
Generating dates:
When you lost your calendar and need to figure out the dates for the next 10 days:
This generates a series of dates starting from right now.
Variable assignment:
For when you want to make sure variables get their values without disturbing DUAL:
Quick calculations:
When you're tired of your calculator and just want to flex some SQL muscles:
Know when to avoid DUAL
Even DUAL needs peace sometimes. In certain scenarios, we can choose not to use it.
Simple PL/SQL operations:
For instance, assigning direct values like this doesn't trouble DUAL:
Handling user-defined types:
When working with collections or user-defined objects, you can manage them directly without involving DUAL.
SPEED UP access with FAST DUAL
Just as the Flash outpaces ordinary mortals, Oracle's DUAL
blazes past regular table access. Stored in memory (not on disk), and optimized via the FAST DUAL access path, DUAL returns date and user data faster than you can say "select star"!
Unleashing performance
When crafting Oracle SELECT statements that don't query real tables, the optimizer deploys its Flash-like FAST DUAL ability, turbocharging data retrieval.
MySQL in comparison
In contrast, MySQL offers fromless syntax, granting you the ability to execute a SELECT without a table:
However, Oracle-based folks would need to get accustomed to DUAL
for similar operations when transitioning from MySQL.
Was this article helpful?