You are on page 1of 1

=============================== Day 5 ========================

Single row functions:-


--------------------
In Oracle we do have different kind of functions
- Single row functions
- Aggregate functions
- Analytical functions
--> In this section we are going to learn single row functions
--> In Aggregate functions it gives only one record from all records, but in single
row functions it gives each and every record.
--- upper, lower, reverse, initcap, length, reverse,
substr - substr(string, starting _position, no_of_char)
instr - It gives the position of the characters.
ex:- select instr('CORPORATE FLOOR','OR',3,2) from dual; --> 14

--> When we have a scenario like below that we need to seperate a record into two
fields based on one character in it.
we can go with with substr and instr
ex :- substr('insurance~200',1,9) from dual - not correct, it works only for
insurance record.
select intr('insurance~200','~') - It gives only the position number
--> In such kind of scenario's we should combine both substr and instr as
below.
ex:- select substr('insurance~200',1,instr('insurance~200','~')-1) from dual;
-- we can give column name instead of hardcoded value.
--- lpad, rpad, ltrim, rtrim, replace, translate, nvl, nvl2, nullif,
coalesce -- we can give n number of arguments it will give first not null value
ex:- nvl(commision_prc,0) -- takes 0 in case of commision value is null.
--- round - it's a numeric function -- <5 -- adds 0, >=5 adds 1
ex:- select round(0.7) from dual; --> 1
select roundd(2.3) from dual; --> 2.3
--- trunc -- it always take the base value only
ex:- select trunc(564.7384,2) from dual; --> 564.73
In Oracle if you are getting any column with timestampa and if you want to get only
date value use truc function
wx:- select trunc(SYSTIMESTAMP) from dual --> 10-MAR-23
--- ceil -it always takes top value
ex:- select ceil(5.00001) from dual --> 6
--- floor - it always gives base value
ex:- select floor(5.99999) --> 5
--- MOTHS_BETWEEN -- gives number of months between two dates
--- days_between, next_day, last_day, add_months
--- to_char -- type casting function converts to string
--- abs -- absolute gives +ve values
ex:- select abs(-365) from dual --> 365

You might also like