0% found this document useful (0 votes)
1K views9 pages

SQL Assignment by U.diwakar 3

The document describes various single-row string and date functions in SQL including UPPER, LOWER, INITCAP, CONCAT, LENGTH, SUBSTR, INSTR, LPAD, RPAD, TRIM, REPLACE, MONTHS_BETWEEN, ADD_MONTHS, LAST_DAY, NEXT_DAY, ROUND, TRUNC, and MOD. Examples are provided for each function to demonstrate how it can be used to manipulate and extract information from strings and dates.

Uploaded by

DIWAKAR U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views9 pages

SQL Assignment by U.diwakar 3

The document describes various single-row string and date functions in SQL including UPPER, LOWER, INITCAP, CONCAT, LENGTH, SUBSTR, INSTR, LPAD, RPAD, TRIM, REPLACE, MONTHS_BETWEEN, ADD_MONTHS, LAST_DAY, NEXT_DAY, ROUND, TRUNC, and MOD. Examples are provided for each function to demonstrate how it can be used to manipulate and extract information from strings and dates.

Uploaded by

DIWAKAR U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SQL ASSIGNMENT

NAME : U.DIWAKAR BCA


BATCH : ONLINE (3PM)
SUBMITTED TO : MOHAMMED MOYN RAZVI SIR
DATE : 30 – 07 – 2021
Single-Row Functions
1)UPPER - Function converts a string to upper
case.
EXAMPLE :-
SELECT UPPER(ENAME) FROM EMP;
UPPER(ENAME)

--------------------

SMITH

ALLEN

WARD

JONES

MARTIN

BLAKE

CLARK

SCOTT

KING

TURNER

ADAMS

JAMES

1
FORD

2)LOWER - Function converts a string to lower


case.
EXAMPLE :-
SELECT LOWER(ENAME) FROM EMP;
LOWER(ENAME)

---------------------

smith

allen

ward

jones

martin

blake

clark

scott

king

turner

adams

james

ford

miller

3)INITCAP - Function converts only the initial


alphabets of a string to upper case.

EXAMPLE :-

2
SELECT INITCAP(ENAME) FROM EMP;

INITCAP(ENAME)

----------------------

Smith

Allen

Ward

Jones

Martin

Blake

Clark

Scott

King

Turner

Adams

James

Ford

Miller

4)CONCAT - Function concatenates two string


values.
EXAMPLE :-
SELECT CONCAT(EMPNO,ENAME) FROM EMP;
CONCAT(EMPNO,ENAME)

-----------------------------------

7369SMITH

7499ALLEN

7521WARD

7566JONES

3
7654MARTIN

7698BLAKE

7782CLARK

7788SCOTT

7839KING

7844TURNER

7876ADAMS

7900JAMES

7902FORD

7934MILLER

5)LENGTH - Function returns the length of the


input string.
EXAMPLE :-
SELECT LENGTH('Structured Query Language')AS
LENGTHOFSTRING FROM DUAL;
LENGTHOFSTRING
------------------------
25

6)SUBSTR - Function returns a portion of a string


from a given start point to an end point.
EXAMPLE :-
SELECT SUBSTR(ENAME,2,4) FROM EMP;
SUBSTR

----------

MITH

LLEN

4
ARD

ONES

ARTI

LAKE

LARK

COTT

ING

URNE

DAMS

AMES

ORD

ILLE

7)INSTR - Function returns numeric position of a


character or a string in a given string.
EXAMPLE :-
SELECT INSTR (ENAME,'A') FROM EMP;
INSTR(ENAME,'A')

------------------------

5
2

8)LPAD and RPAD - Functions pad the given string


upto a specific length with a given character.
EXAMPLE :-
SELECT RPAD(ENAME,8,'**')
||LPAD(EMPNO,6,'**') FROM EMP;
RPAD(ENAME)||LPAD(EMPNO)

------------------------------------------

SMITH*****7369

ALLEN*****7499

WARD******7521

JONES*****7566

MARTIN****7654

BLAKE*****7698

CLARK*****7782

SCOTT*****7788

KING******7839

TURNER****7844

ADAMS*****7876

JAMES*****7900

FORD******7902

MILLER****7934

9)TRIM - Function trims the string input from the


start or end.
EXAMPLE :-
6
SELECT TRIM(' structured query language ') AS
TrimmedString FROM DUAL;
TRIMMEDSTRING

---------------------------------

structured query language

10)REPLACE - Function replaces characters from


the input string with a given character.
EXAMPLE :-
SELECT REPLACE('SQL FUNCTIONS', 'SQL',
'SCHOOL')FROM DUAL;
REPLACE('SQL FUNCTIONS’)

-------------------------------------

SCHOOL FUNCTIONS

11)MONTHS_BETWEEN - Function returns the


count of months between the two dates.

EXAMPLE :-
SELECT MONTHS_BETWEEN ('31-MAR-1995', '28-
FEB-1994') FROM DUAL;

MONTHS_BETWEEN('31-MAR-1995','28-FEB-1994')
--------------------------------------------------------------------
13

7
12)ADD_MONTHS - Function add 'n' number of
months to an input date.
EXAMPLE :-
SELECT ADD_MONTHS ('16-Sep-81', 3)FROM
DUAL;
ADD_MONTH
------------------
16-DEC-81

13)LAST_DAY - Function returns last day of the


month of the input date.
EXAMPLE :-
SELECT LAST_DAY ('01-JAN-1980')FROM DUAL;
LAST_DAY('01-JAN-1980')
---------------------------------
31-JAN-80

14)NEXT_DAY - Function returns the next day of


the date specified.
EXAMPLE :-
SELECT NEXT_DAY ('01-Jun-91',
'Wednesday')FROM DUAL;
NEXT_DAY('01-Jun-08', 'Wednesday')
--------------------------------------------------
04-JUN-91

8
15)ROUND and TRUNC - Functions are used to
round and truncate the number value.
EXAMPLE :-
SELECT ROUND(3.456) FROM DUAL;
ROUND(3.456)
------------------
3

SELECT TRUNC(1456.967) FROM DUAL;


TRUNC(1456.967)

-----------------------

1456

16)MOD - Functions used to return the remainder


of the division operation between two numbers.
EXAMPLE :-
SELECT MOD( 90,7) FROM DUAL
MOD(90,7)
----------=
6

You might also like