Sunday, August 2, 2020

[Orcale][Example] DUAL table

DUAL table is is a special one-row (by default value is X), one column (data type VARCHAR2(1)) table which with used for evaluating expressions or calling functions., it also the most simple table designed for fast access

Example 1: SELECT * mean do nothing 
SELECT * FROM dual;
---------------
|    DUMMY    |
---------------
|      X      |
---------------
From the result we can found the default setting of DUAL table: column name: DUMMY, and field value is X.


Example 2: Show string
SELECT 'Hello' FROM dual;
--------------------
|   |    'HELLO'   |
--------------------
| 1 |    'Hello'   |
--------------------

Example 3: Show number
SELECT 4 FROM dual;
-----------
|   |  4  |
-----------
| 1 |  4  |
-----------

Example 4: Show current user
SELECT USER FROM dual;
------------------
|   |    USER    |
------------------
| 1 |  SYSADMIN  |
------------------

Example 5: Show current Oracle date
SELECT SYSDATE FROM dual;
---------------------
|   |    SYSDATE    |
---------------------
| 1 |   03-8月 -20  |
---------------------

Example 6: Show string with build-in function
SELECT UPPER('Hello') FROM dual;
-----------------------
|   |  UPPER('HELLO') |
-----------------------
| 1 |    'HELLO'      |
-----------------------

Example 7: Show expression calculation result by accesss the DUAL table:
SELECT 1000+999 FROM dual;
------------------
|   |  1000+999  |
------------------
| 1 |    1999    |
------------------

Reference:

No comments :

Post a Comment