Monday, August 16, 2010

Oracle 11g: Conversion Functions

===> SQL Queries:  TO_CHAR with Dates

select last_name,
       to_char(hire_date,'fmDD Month YYYY') as hiredate
from employees


Results:

LAST_NAME                 HIREDATE         
------------------------- -----------------
King                      17 June 1987     
Kochhar                   21 September 1989
De Haan                   13 January 1993  
Hunold                    3 January 1990   
Ernst                     21 May 1991      
Austin                    25 June 1997     
Pataballa                 5 February 1998  
Lorentz                   7 February 1999  
Greenberg                 17 August 1994   
Faviet                    16 August 1994   
Chen                      28 September 1997
Sciarra                   30 September 1997
Urman                     7 March 1998     
Popp                      7 December 1999  
Raphaely                  7 December 1994  
Khoo                      18 May 1995      
Baida                     24 December 1997 
Tobias                    24 July 1997     
Himuro                    15 November 1998 
Colmenares                10 August 1999   
Weiss                     18 July 1996     
Fripp                     10 April 1997    
Kaufling                  1 May 1995       
Vollman                   10 October 1997  
Mourgos                   16 November 1999 
Nayer                     16 July 1997     
Mikkilineni               28 September 1998
Landry                    14 January 1999  
Markle                    8 March 2000     
Bissot                    20 August 1997   
Atkinson                  30 October 1997  
Marlow                    16 February 1997 
Olson                     10 April 1999    
Mallin                    14 June 1996     
Rogers                    26 August 1998   
Gee                       12 December 1999 
Philtanker                6 February 2000  
Ladwig                    14 July 1995     
Stiles                    26 October 1997  
Seo                       12 February 1998 
Patel                     6 April 1998     
Rajs                      17 October 1995  
Davies                    29 January 1997  
Matos                     15 March 1998    
Vargas                    9 July 1998      
Russell                   1 October 1996   
Partners                  5 January 1997   
Errazuriz                 10 March 1997    
Cambrault                 15 October 1999  
Zlotkey                   29 January 2000  
Tucker                    30 January 1997  
Bernstein                 24 March 1997    
Hall                      20 August 1997   
Olsen                     30 March 1998    
Cambrault                 9 December 1998  
Tuvault                   23 November 1999 
King                      30 January 1996  
Sully                     4 March 1996     
McEwen                    1 August 1996    
Smith                     10 March 1997    
Doran                     15 December 1997 
Sewall                    3 November 1998  
Vishney                   11 November 1997 
Greene                    19 March 1999    
Marvins                   24 January 2000  
Lee                       23 February 2000 
Ande                      24 March 2000    
Banda                     21 April 2000    
Ozer                      11 March 1997    
Bloom                     23 March 1998    
Fox                       24 January 1998  
Smith                     23 February 1999 
Bates                     24 March 1999    
Kumar                     21 April 2000    
Abel                      11 May 1996      
Hutton                    19 March 1997    
Taylor                    24 March 1998    
Livingston                23 April 1998    
Grant                     24 May 1999      
Johnson                   4 January 2000   
Taylor                    24 January 1998  
Fleaur                    23 February 1998 
Sullivan                  21 June 1999     
Geoni                     3 February 2000  
Sarchand                  27 January 1996  
Bull                      20 February 1997 
Dellinger                 24 June 1998     
Cabrio                    7 February 1999  
Chung                     14 June 1997     
Dilly                     13 August 1997   
Gates                     11 July 1998     
Perkins                   19 December 1999 
Bell                      4 February 1996  
Everett                   3 March 1997     
McCain                    1 July 1998      
Jones                     17 March 1999    
Walsh                     24 April 1998    
Feeney                    23 May 1998      
OConnell                  21 June 1999     
Grant                     13 January 2000  
Whalen                    17 September 1987
Hartstein                 17 February 1996 
Fay                       17 August 1997   
Mavris                    7 June 1994      
Baer                      7 June 1994      
Higgins                   7 June 1994      
Gietz                     7 June 1994      

107 rows selected

===> SQL Queries:  TO_CHAR with Numbers

select to_char(salary,'$99,999.00') salary
from employees
where last_name = 'Ernst'

Results:
SALARY     
-----------
  $6,000.00

1 rows selected

===> SQL Queries:  TO_DATE using RR

select last_name,TO_CHAR(hire_date, 'DD-Mon-YYYY')
from employees
where hire_date < TO_DATE('01-Jan-90','DD-Mon-RR')

Results:
LAST_NAME                 TO_CHAR(HIRE_DATE,'DD-MON-YYYY')
------------------------- --------------------------------
King                      17-Jun-1987                     
Kochhar                   21-Sep-1989                     
Whalen                    17-Sep-1987                     

3 rows selected

No comments: