Results 1 to 3 of 3

Thread: Dual Table

  1. #1
    Join Date
    Feb 2006
    Posts
    46

    Unanswered: Dual Table

    What does the Dual table exactly do?

    Thanks.

  2. #2
    Join Date
    Nov 2003
    Posts
    5

  3. #3
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    565
    Oracle SQL syntax requires a FROM clause. Therefore if you just want to return the system date or some other value that does not come from an actual database table, you still need a row from a table to drive the SQL query. DUAL is just a table containing one row that you can use in this type of query:

    Code:
    -- There has to be a FROM clause:
    SQL> SELECT 4 * 3;
    SELECT 4 * 3
               *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    
    
    -- Any table will do, but you only want one row back:
    SQL> SELECT 4 * 3 FROM scott.dept;
    
           4*3
    ----------
            12
            12
            12
            12
            12
    
    5 rows selected.
    
    -- You can rely on DUAL only having one row:
    SQL> SELECT 4 * 3 FROM dual;
    
           4*3
    ----------
            12
    
    1 row selected.
    
    -- It's just a regular table, though:
    SQL> set lines 50
    SQL> desc dual
     Name                    Null?    Type
     ----------------------- -------- ----------------
     DUMMY                            VARCHAR2(1)
    Actually that isn't quite true - the database is aware of DUAL and has a couple of optimizations that can allow it to avoid an actual query internally.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •