Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select without a FROM clause in Oracle

Tags:

sql

oracle

in SQL Server is possible to execute a SELECT, without reference to a table; something like:

Select 1.2 +3, 'my dummy string' 

As Oracle does not allow a SELECT without a FROM, I use the dual table for this type of operation; something like:

Select 1,2+3, 'my dummy string' FROM DUAL 

There is a better way of doing this type of query? it is good practice to use the dual table?

like image 924
RRUZ Avatar asked Dec 10 '09 15:12

RRUZ


People also ask

Can you write a SELECT query without the FROM clause in Oracle?

To select values from SQL expressions, a FROM clause is not strictly required as the expression is not selected from that table anyway.

Do you need a from statement in SQL?

This depends on the database. In Oracle, IIRC, the from is required. But Oracle has a table DUAL which always returns one row for cases where all the work is being done in the SELECT clause.

What happens if you run a SELECT statement without a WHERE clause?

Using SELECT without a WHERE clause is useful for browsing data from tables. In a WHERE clause, you can specify a search condition (logical expression) that has one or more conditions. When the condition (logical expression) evaluates to true the WHERE clause filter unwanted rows from the result.

Does SELECT * Work in Oracle?

If you use the asterisk (*) in the application code and assume that the table has a fixed set of columns, the application may either not process the additional columns or access the removed columns.


1 Answers

No, in Oracle there is no SELECT without FROM.

Using the dual table is a good practice.

dual is an in-memory table. If you don't select DUMMY from it, it uses a special access path (FAST DUAL) which requires no I/O.

Once upon a time, dual had two records (hence the name) and was intended to serve as a dummy recordset to duplicate records being joined with.

Now it has but one record, but you can still generate an arbitrary number of rows with it:

SELECT  level FROM    dual CONNECT BY         level <= 100 

MySQL also supports dual (as well as the fromless syntax).

like image 129
Quassnoi Avatar answered Sep 21 '22 17:09

Quassnoi