Professional Documents
Culture Documents
Date:
Experiment No:3
3.)Queries to facilitate acquaintance of Built-in Functions: String Functions,
Numeric Functions, Date Functions and Conversion Functions.
Aim: To facilitate acquaintance of Built-in Functions: String Functions, Numeric
Functions, Date Functions and Conversion Functions.
Description:
String Functions:
Length():
This function is used to find the length of a word.
Syntax:
Select length(“String_name”) from dual;
Lower():
This function is used to convert the upper case string into lower case.
Syntax:
select lower(“string_name”) from dual;
LPAD():
This function is used to make the given string of the given sizeby adding the
given symbol.
Syntax:
select lpad(‘string_name’,num,’string’) from dual;
LTRIM():
This function is used to cut the given sub string from theoriginal string.
Syntax:
select ltrim(‘string_name’,’string’) from dual;
CONCAT():
This function is used to add two words or strings.
Syntax:
select concat(‘string_name’,’another_string’) from dual;
MID():
This function is to find a word from the given position and ofthe given size.
Syntax:
select mid(‘string_name’,num,num) from dual;
POSITION():
This function is used to find position of the first occurrence ofthe given
alphabet.
Syntax:
select position(‘character’ in ’string’) from dual;
REPEAT():
This function is used to write the given string again and againtill the number
of times mentioned.
Syntax:
select repeat(‘string_name’,num) from dual;
REPLACE():
This function is used to cut the given string by removing thegiven sub
string.
Syntax:
select replace (‘string_name’,’string’) from dual;
REVERSE ():
This function is used to reverse a string.
Syntax:
select reverse(‘string_name’) from dual;
RPAD():
This function is used to make the given string as long as thegiven size by
adding the given symbol on the right.
Syntax:
select rpad(‘string_name’,num,’string’) from dual;
RTRIM():
This function is used to cut the given sub string from the originalstring.
Syntax:
select rtrim(‘string_name’,’string’) from dual;
SUBSTR():
This function is used to find a sub string from the a string fromthe given
position.
Syntax:
Select substr(‘string_name’, start_index, end_index) from dual;
Queries:
LENGTH():
LOWER ():
LOWER(
-----------------------
reddys
LPAD():
LPAD(‘AD
-----------------------
**aditya
LTRIM():
LTRIM(
-----------------------
Aditya
CONCAT():
SQL> select concat(‘satya’,’narayana’) from dual;
CONCAT('SATYA
-------------
Satyanarayana
REPLACE():
SQL> select replace('reddysatyareddy', 'reddy') from dual;
REPLA
-----
Satya
REVERSE ():
SQL> select reverse('sydder') from dual;
REVERS
------
reddys
RPAD():
SQL> select rpad('aditya',10,'*') from dual;
RPAD('ADIT
----------
aditya****
Numeric Functions:
max():
To get the maximum value from the table in a column.
Syntax:
select max(<column_name>) from <table_name>;
min():
To get the minimum value from the table in a column.
Syntax:
select min(<column_name>) from <table_name>;
sum():
To get the addition of values from the table in a column.
Syntax:
select sum(<column_name>) from <table_name>;
avg():
To get the average of values from the table in a column.
Syntax:
select avg(<column_name>) from <table_name>;
ceil():
It round of the decimal value to the next value.
Syntax:
select ceil(<decimal value>) from dual;
floor():
It round of the decimal value to the below value.
Syntax:
select floor(<decimal value>) from dual;
Queries:
max():
SQL> select max(age) from Names;
MAX(AGE)
----------
23
min():
SQL> select min(age) from Names;
MIN(AGE)
----------
20
sum():
SQL> select sum(age) from Names;
SUM(AGE)
----------
86
avg():
SQL> select avg(age) from Names;
AVG(AGE)
----------
21.5
ceil():
SQL> select ceil(4.4) from dual;
CEIL(4.4)
----------
5
floor():
SQL> select ceil(4.4) from dual;
CEIL(4.4)
----------
5
Date functions:
sysdate():
To view the system date.
Query:
SQL> select sysdate from dual;
SYSDATE
---------
10-FEB-24
last_day():
To view the last day from the month.
Query:
SQL> select last_day(sysdate) from dual;
LAST_DAY(
---------
29-FEB-24
add_months():
To add the months from the current month.
Query:
SQL> select to_char(add_months(sysdate,2))from dual;
TO_CHAR(ADD_MONTHS
------------------
10-APR-24
next_day():
To get next coming from the current date.
Query:
SQL> select to_char(next_day(sysdate,'sat')) from dual;
TO_CHAR(NEXT_DAY(S
------------------
17-FEB-24