Oracle_4
Oracle_4
i) Sysdate:
It displays the system date and time
We can use date functions by adding and subtracting values from a date function.
The current date function returns the current date in the time zone of current sql session as set by the
alter session command
Note: we have to alter the session and time zone to use current_date
iii) Add_months:
iV) Months-between:
V. Next_day:
Vi. Last_day:
Note: In the above examples fm means format_mask parameter. It means the zeros and blanks are
suppressed
Parameter/Format Explanation
yyyy 4 digit year
yyy or yy or y last 3 or 2 or 1
mon abbreviated month (jan-dec)
month name of the month (January-December)
day name of day
dd day of month(1-31)
ddd day of year (1-31)
hh hour of day (1-12)
hh24 hour of day (0-23)
mi minutes (0-59)
ss (0-59)
year to write the complete year name
ii) to_date:
iii) to_number:
ii) Uid:
Select uid from dual;
iii) NVL:
It is used to replace the null values of a column with given value.
Syn: nvl (col_name, replacement value)
Ex: select nvl (sal,10000) from emp;
The above command replaces the null values of sal column with values of 10000
iv)NVL2:
It is extended functionality of nvl function.
It allows you to substitute a value when a null is encountered as well as not null values is encountered
V)Null if:
The null-if function compares expr1 and expr2.
If expr1 and expr2 are equal it returns null, It expr1 and expr2 not equal it returns expr1
Vi) Coalesce:
The coalesce function returns the first non-null expression in the list. If all expressions evaluate to null
then the coalesce function will return null.
Syn: coalesce (expr1,expr2,…..exprn);
Ex: coalesce (empname1, empname2, empname3) from emp;
In the above example if empname is not null it will display empname1
If empname1 is null, if empname2 is not-null it will display empname2
If empname1 and empname2 is null, if empname3 is not null it will display empname3;
If all nulls it will display null only.
Vii) Case:
.
.
.
In the simple case expression oracle database searches for the comparison expression then return the
corresponding statement.
Example:
Select cust-last-name, case credit-limit
When 1000 then low
When 5000 then high
Else medium END
From emp;
The simple case performance a simple equality check of expression against each of the when options.
The searched case evaluates the conditions independently under each of the when options, more
complex conditions can be implemented with search case
A searched case can combine multiple tests using and.
Viii) Decode:
It has the functionality of if-then-else statement using decode function we can substitute value with
another value.
Syn: Decode ( col_name, value, result, value, result, value,….. default value)
Here default value used to replace the other values with default value, If we don’t specify the default
value it will replaces the rest of values as null
Ex: select decode (S-area, ‘bellandur’, ‘karnataka’, ‘rct’, ‘a.p’, ‘chennai’, ‘t.n’ , ‘rest of india’) from
table_name;
The above function replaces s-area column where Bellandur with Karnataka, Rct with A.P , Chennai with
T.N and other values with rest of India
Decode and case statements both give values based on condition, like it-then-else
àIn case function we can use logical all operators including =,<>,>,< and all other operators
But in decode function we cannot use any operators we can use equity check condition
àCase expects datatype consistency and decode does not expect datatype consistency.