0% found this document useful (0 votes)
6 views

DBMS

Uploaded by

srk.itdept
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

DBMS

Uploaded by

srk.itdept
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT-4

AIM:Queries to facilitate acquaintance of Built-In Functions, String Functions, Numeric


Functions, Date Functions and Conversion Functions.
DESCRIPTION:

1 .Character Functions:
Upper Returns char with all letters into upper case
Lower Converts the mixed case or uppercase character strings to lowercase
Converts the first letter of each word to upper case and remaining letters to
Initcap
lowercase
Concat Joins values together you are limited to two arguments with concat
Substr This extracts a string of determined length
Length Shows the length of a string as a numeric value
Instr Finds numeric position of named character
Lpad Pads the character value right justified
Rpad Pads the character value left justified
Trim Trims heading or trailing characters from a character string
Raplace To replace a set of character (String based)
Translate Change a character to a new described character(character based)

PROGRAM:

SQL> select upper ('oracle') from dual;


UPPER
------
ORACLE

SQL> select lower ('ORACLE') from dual;


LOWER
------
oracle

SQL>select initcap('sql functions') from dual;


initcap
-------------
Sql Functions

SQL>select concat('sql','functions') from dual;


CONCAT('SQL'
------------
Sqlfunctions

SQL> select substr('sqlfunctions',1,5) from dual;


SUBST
-----
Sqlfu

SQL> select substr('sqlfunctions',2,5) from dual;


SUBST
-----
qlfun
SQL> select substr('sqlfunctions',4,5) from dual;
SUBST
-----
funct

SQL> select length('sqlfunctions') from dual;

LENGTH('SQLFUNCTIONS')
----------------------
12

SQL> select instr('sqlfunctions','f') from dual;


INSTR('SQLFUNCTIONS','F')
-------------------------
4
SQL> select lpad(sql,8,'*') from dual;
LPAD(SQL,8,'*'
---------------
*****sql
SQL> select rpad(sal,8,'*') from dual;
RPAD(SQL,8,'*'
---------------
Sql*****
SQL> select trim('s' from 'ssmiths') from dual;
TRIM
----
mith
SQL> select ltrim('ssmiths','s') from dual;
LTRIM
-----
miths
SQL> select rtrim('ssmiths','s') from dual;
RTRIM(
------
ssmith
SQL>select replace('jack ,'j','bl') from dual;
REPLACE('JACK
--------------
black
SQL>select translate('jack','j','b') from dual;
TRAN
----
Back
2.Number Functions:

Round Rounds the value to specified decimal


Trunc Truncates the column, expression, or value to n decimal
places
Power Calculates the power of the given value
Mod Finds the remainder of value1 divided by value1
Ceil Takes the height decimal value
Floor Takes the lowest decimal value

PROGRAM:

SQL> select round(35.823)from dual;

ROUND(35.823)
-------
36

SQL> select trunc(35.823,2) from dual;

TRUNC(35.823,2)
---------------
35.82

SQL> select mod(5,2) from dual;


MOD(5,2)
----------
1

SQL> select mod(4,2) from dual;

MOD(4,2)
-------------
0

SQL> select ceil(35.23)from dual;

CEIL(35.23)
----------- -
36

SQL> select floor(35.23) from dual;

FLOOR(35.23)
------------
35

SQL>select (2+3) from dual;


o/p:5
SQL>
Select(6-3) from dual;
o/p:3
SQL>
SELECT(2*3) FROM DUAL;
O/P:6

3.Date Functions:

SYSDATE is a pseudo column that returns the current date and time. When we select
sysdate it will display in a dummy table called DUAL. Oracle date range between 1 stjan
4712 BC and 31st Dec 4712 AD.

Months_between It returns the numeric value. Finds the no. of months between
date1 and date2, result may be positive or negative.
Add_months It returns the date datatype. Adds n number of calendar months
to date, n must be an integer and it can be negative
Last_day It returns the date datatype. Date of the
Next_day It returns the date datatype. Date of the next specified day of the
week following date1, char may be number representing a day,
or a character

PROGRAM:

SQL>select sysdate from dual;


SYSDATE
---------
08-JUL-10
SQL>select lower(sysdate) from dual;

LOWER(SYS

SQL>select months_between(sysdate, ’12-dec-2021’) from dual;

MONTHS_BETWEEN(SYSDATE,’12)
--------------------------------
-8.444
SQL> select months_between('01-jan-2010', sysdate) from dual;

MONTHS_BETWEEN('01-JAN-2010',SYSDATE)
-------------------------------------
-6.2451325

SQL> select last_day(sysdate) from dual;

LAST_DAY(
---------
31-JUL-10
SQL>select next_day(sysdate, 'friday') from dual;

NEXT_DAY(
---------
09-JUL-10
SQL>select extract(day from sysdate) from dual;
EXTRACT(DAY FROM SYS
-------
12

SQL>select extract(month from sysdate) from dual;


EXTRACT(MONTH FROM SYS
-------
APR

SQL>select extract(year from sysdate) from dual;


EXTRACT(YEAR FROM SYS
-------
2021

You might also like