2. How does choosing from DUAL give system time?
SQL has a number of built-in functions that do not require parentheses after they are called. One such feature in Oracle is SYSDATE.
Remember that if you have a table, a SELECT statement without a constraint condition (WHERE clause) usually returns one row of data for each row in the table. So, given the table:
CREATE TABLE Ex1(Dummy CHAR(10) NOT NULL); INSERT INTO Ex1 VALUES('Abacus'); INSERT INTO Ex1 VALUES('Sedentary'); INSERT INTO Ex1 VALUES('Caucasus');
Running the SELECT statement:
SELECT Dummy FROM Ex1;
will return 3 rows. Now suppose I write the expression as:
SELECT 'ABC', Dummy, SYSDATE FROM Ex1;
This will also return 3 lines:
- ABC, Abacus, 2010-03-03
- ABC, Sedentary, 2010-03-03
- ABC, Caucasus, 2010-03-03
If I omit the Dummy column:
SELECT 'ABC', SYSDATE FROM Ex1;
I get:
- ABC, 2010-03-03
- ABC, 2010-03-03
- ABC, 2010-03-03
And if I omit the string literal:
SELECT SYSDATE FROM Ex1;
I get:
- 2010-03-03
- 2010-03-03
- 2010-03-03
And I delete the two lines and re-run the request, I get:
DELETE FROM Ex1 WHERE Dummy > 'B'; SELECT SYSDATE FROM Ex1;
I get:
Because there is only one row of data in the table Ex1.
Nominally, I could do:
UPDATE Ex1 SET Dummy = 'X'; RENAME TABLE Ex1 AS Dual;
Of course you cannot do this - I'm not sure if Oracle supports the RENAME TABLE statement, and this probably will not allow you to rename your table so that it can be confused with the built-in DUAL table. But conceptually, the Ex1 table with one row in it is isomorphic to DUAL.
1. What is a pseudo-column?
Unless Oracle has a special meaning for this term, a pseudo-column is a column that appears to be part of a table but is not actually stored as data in a table. A classic example is the line number:
SELECT ROWNUM, * FROM SomeTable
The output column appears ROWNUM (ROWID in Informix, with which I am most familiar), but it is not stored directly in the DBMS. Different DBMSs have different pseudo-columns for different purposes.
Sometimes it is difficult to distinguish between a pseudocolonomer and a function.