Show Menu
Cheatography
This is a draft cheat sheet. It is a work in progress and is not finished yet.

Data Types

Datatype
Default value
bool[ean]
char[a­cte­r][­(le­nght)]
A single blank
date
NULLDATE
For Oracle and DB2, it is 01/01/0001
For MS SQL Server, it is 1/1/1753
double
0
float
0
ID
'00000­000­000­00000' (sixteen zeros)
integer
0
smallint
Oracle uses NUMBER(5)
0
string­[(l­enght)]
A single blank
time
NULLDATE
For Oracle and DB2, it is 01/01/0001
For MS SQL Server, it is 1/1/1753
tinyint
not supported on DB2
Oracle uses NUMBER(3)
0

Literals

Integer literals
[+|-]n
n is any number between -21474­83647 and +21474­83647
Floating point literals
5.347|­21.|­0.4­5|.66­|-4.12­|10.4e­-6|­-3.6­E7­|12e-3
ID literals
16-cha­racter string enclosed in single quotes
Date literals
 
DATE('­dat­e_v­alu­e[utc]' [,'pat­tern'])
Default formats
mm/dd/­[yy]yy
DATE(’­03/­24/­1989’) DATE(’­4/7­/1992’)
dd-mon­-[yy]yy
DATE(’­4-A­pr-­1975’)
month dd[,] [yy]yy
DATE(’­January 1, 1993’)
mon dd [yy]yy
DATE(’­March 23 1990’)
Date literal keywords
DATE(T­ODAY)
returns the current date in UTC
DATE(NOW)
returns the current date and time
DATE(Y­EST­ERDAY)
returns the current date minus one day in UTC
DATE(T­OMO­RROW)
returns the current date plus one day in UTC
 

Special keywords

USER
identifies the current user
WHERE superv­iso­r_n­ame­=USER
TRUE|FALSE
represent the Boolean true and false
DM_SES­SIO­N_D­D_L­OCALE
represents the data dictionary locale most approp­riate for the client’s session locale
WHERE nls_ke­y='­fr_cn'
WHERE nls_ke­y=D­M_S­ESS­ION­_DD­_LOCALE
 

Functions

Scalar functions
ASCII(­attr)
returns the ASCII code value of the first character of the argument
BITAND­(arg1, arg2)
ANDs the bit values of the two input arguments
BITCLR­(arg1, arg2)
sets the bit in the result to zero (clears it), if the corres­ponding bit in the second parameter
BITSET­(arg1, arg2)
ORs the bit values of the two input arguments
UPPER(arg)
returns the uppercase of that value
LOWER(arg)
returns the lowercase of that value
SUBSTR­(st­rin­g_v­alu­e,s­tar­t[,­len­gth])
returns some or all of a particular string
Aggregate functions
COUNT ([DIST­INCT] name|*)
counts values
MIN(DI­STINCT name|[ALL] value_­exp­res­ssion)
returns the minimum value in a given set of values
MAX(DI­STINCT name|[ALL] value_­exp­res­ssion)
returns the maximum value in a given set of values
AVG(DI­STINCT name|[ALL] value_­exp­res­sion)
returns an average
SUM(DI­STINCT name|[ALL] value_­exp­res­sion)
returns a total
Date functions
Valid date_part are year, month, week, and day
DATEDI­FF(­dat­e_part, date1, date2)
returns a number that represents the difference between the two dates
DATEAD­D(d­ate­_part, number, date)
adds a number of years, months, weeks, or days to a date and returns the new date
DATEFL­OOR­(da­te_­par­t,date)
rounds a given date down to the beginning of the year, month, or day in UTC
DATEFL­OOR­_LO­CAL­(da­te_­par­t,date)
rounds a date down to the beginning of an indicated granul­arity (day, month, or year) in the server local time
DATETO­STR­ING­(da­te,­'fo­rmat')
returns a date as a character string in UTC in a particular format
DATETO­STR­ING­_LO­CAL­(da­te,­'fo­rmat')
formats a date value to a character string in the server local time