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

EX2C

The document outlines procedures for implementing single row functions in SQL including character, numeric, and date functions. It provides examples of lower, upper, initcap, concat, length, substr, instr, lpad, rpad, trim, replace and other character functions. For numeric functions, examples include abs, acos, asin, atan, ceil, floor, greatest, least, mod, power, round, and truncate. Date function examples cover addition/subtraction of dates, months_between, add_months, next_day, last_day, round, and trunc. The aim was achieved by executing these single row functions.

Uploaded by

Manendra
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)
7 views

EX2C

The document outlines procedures for implementing single row functions in SQL including character, numeric, and date functions. It provides examples of lower, upper, initcap, concat, length, substr, instr, lpad, rpad, trim, replace and other character functions. For numeric functions, examples include abs, acos, asin, atan, ceil, floor, greatest, least, mod, power, round, and truncate. Date function examples cover addition/subtraction of dates, months_between, add_months, next_day, last_day, round, and trunc. The aim was achieved by executing these single row functions.

Uploaded by

Manendra
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/ 7

AIM:

Implement Single Row functions - Character, Numeric and Date functions.

PROCEDURE:
1. CHARACTER SINGLE ROW FUNCTIONS:

A. Case Manupilative Functions:


LOWER:
Purpose:
This function converts alpha character values to lowercase.
Example Queries:
SQL> SELECT LOWER('SQL QUERIES') FROM DUAL;
Output1:
sql queries
SQL> SELECT LOWER('DATABASE@123') FROM DUAL;
Output2:
database@123

.UPPER:
Purpose:
This function converts alpha character values to uppercase.
Example Queries:
SQL> SELECT UPPER('sql queries') FROM DUAL;
Output:
SQL QUERIES
SQL>SELECT UPPER('dbms$255%7') FROM DUAL;
Output:
DBMS$255%7

.INITCAP:
Purpose:
This function converts alpha character values to uppercase for the first letter of each word and all
others in lowercase.
Example Queries:
SQL> SELECT INITCAP('this is a computer science department') FROM DUAL;
Output:
This Is A Computer Science Department
SQL> SELECT INITCAP('PRACTICE_CODING_FOR_EFFICIENCY') FROM DUAL;
Output:
Practice_Coding_For_Efficiency

B.Character Manupilative Functions:

. CONCAT:
Purpose:
This function always appends ( concatenates ) string2 to the end of string1.
Syntax:
CONCAT('String1', 'String2')
Example Queries:
SQL> SELECT CONCAT('computer' ,'science') FROM DUAL;
Output: computerscience
SQL> SELECT CONCAT( NULL ,'Android') FROM DUAL;
Output: Android
SQL> SELECT CONCAT( NULL,NULL ) FROM DUAL;
Output: -

.LENGTH:
Purpose:
This function returns the length of the input string.
Syntax:
LENGTH(Column|Expression)
SQL> SELECT LENGTH('Learning Is Fun') FROM DUAL;
Output:
15
SQL> SELECT LENGTH(' Write an Interview Experience ') FROM DUAL;
Output:
34
SQL> SELECT LENGTH('') FROM DUAL; or SELECT LENGTH( NULL ) FROM DUAL;
Output: -

. SUBSTR:
purpose:
This function returns a portion of a string from a given start point to an end point.
Syntax:
SUBSTR('String',start-index,length_of_extracted_string)
SQL> SELECT SUBSTR('Database Management System', 9) FROM DUAL;
Output:
Management System
SQL> SELECT SUBSTR('Database Management System', 9, 7) FROM DUAL;
Output:
Manage

.INSTR:
Purpose:
This function returns numeric position of a character or a string in a given string.
Syntax: INSTR(Column|Expression, 'String', [,m], [n])
Input: SELECT INSTR('Google apps are great applications','app',1,2) FROM DUAL;
Output: 23

. LPAD and RPAD:


Purpose:
These functions return the strings padded to the left or right ( as per the use ).
Syntax:
LPAD(Column|Expression, n, 'String')
SQL> LPAD Input1: SELECT LPAD('100',5,'*') FROM DUAL;
LPAD Output:
**100
SQL> SELECT LPAD('hello', 29, 'MBUCSE') FROM DUAL;
LPAD Output:
MBUCSEMBUCSEMBUCSEMBUCSEhello
Syntax:
RPAD(Column|Expression, n, 'String')
SQL> SELECT RPAD('5000',7,'*') FROM DUAL;
RPAD Output:
5000***
SQL> SELECT RPAD('earn', 19, 'SKILL') FROM DUAL;
RPAD Output:
earnSKILLSKILLSKILLSKILL

. TRIM:
Purpose:
This function trims the string input from the start or end (or both).
Syntax:
TRIM(Leading|Trailing|Both, trim_character FROM trim_source)
SQL> SELECT TRIM('M' FROM 'MBUCSE') FROM DUAL;
Output:
BUCSE
SQL> SELECT TRIM(' MBUCSE ') FROM DUAL;
Output:
MBUCSE

. REPLACE:
Purpose:
This function searches for a character string and, if found, replaces it with a given replacement string
at all the occurrences of the string.
Syntax:
REPLACE(Text, search_string, replacement_string)
SQL> SELECT REPLACE('DATA MANAGEMENT', 'DATA','DATABASE') FROM DUAL;
Output:
DATABASE MANAGEMENT

Input2: SELECT REPLACE('MISSISSIPPI', 'IS') FROM DUAL;


Output2: MSSIPPI

2. NUMERIC SINGLE ROW FUNCTIONS:

A. ABS();
Purpose:
It returns the absolute value of a number.
SQL> SELECT ABS(-10) FROM DUAL;
Output:
ABS(-10)
--------------
10

B. ACOS():
It returns the cosine of a number, in radians.
SQL> SELECT ACOS(0.25) FROM DUAL;
ACOS(0.25)
----------
1.31811607

C. ASIN():
It returns the arc sine of a number, in radians.
SQL> SELECT ASIN(0.25) FROM DUAL;

ASIN(0.25)
----------
.252680255

D. ATAN():
It returns the arc tangent of a number, in radians.
SQL> SELECT ATAN(2.5) FROM DUAL;

ATAN(2.5)
----------
1.19028995

E. CEIL():
It returns the smallest integer value that is greater than or equal to a number.
SQL> SELECT CEIL(25.75) FROM DUAL;

CEIL(25.75)
-----------
26

F. CEILING():
It returns the smallest integer value that is greater than or equal to a number.
SQL> SELECT CEIL(25.75) FROM DUAL;

CEIL(25.75)
-----------
26

G. COS():
It returns the cosine of a number, in radians.
SQL> SELECT COS(30) FROM DUAL;

COS(30)
----------
.15425145

H. FLOOR():
It returns the largest integer value that is less than or equal to a number.
SQL> SELECT FLOOR(25.75) FROM DUAL;

FLOOR(25.75)
------------
25
I. GREATEST():
It returns the greatest value in a list of expressions.
SQL> SELECT GREATEST(30, 2, 36, 81, 125) FROM DUAL;

GREATEST(30,2,36,81,125)
------------------------
125

J. LEAST():
It returns the smallest value in a list of expressions.
SQL> SELECT LEAST(30, 2, 36, 81, 125) FROM DUAL;

LEAST(30,2,36,81,125)
---------------------
2

K. MOD():
It returns the remainder (aka. modulus) of n divided by m.
SQL> SELECT MOD(18, 4) FROM DUAL;

MOD(18,4)
----------
2

L.POWER(m, n):
It returns m raised to the nth power.
SQL> SELECT POWER(4, 2) FROM DUAL;

POWER(4,2)
----------
16

M. ROUND():
It returns a number rounded to a certain number of decimal places.
SQL> SELECT ROUND(5.553,1) FROM DUAL;
ROUND(5.553,1)
--------------
5.6

SQL> SELECT ROUND(5.553,2) FROM DUAL;


ROUND(5.553,2)
--------------
5.55

SQL> SELECT ROUND(65.553,-1) FROM DUAL;


ROUND(65.553,-1)
----------------
70
N. TRUNCATE(): This doesn’t work for SQL Server. It returns 7.53635 truncated to n places right of
the decimal point.
SQL> SELECT TRUNC(753.53635, -1) FROM DUAL;
TRUNC(753.53635,-1)
-------------------
750

SQL> SELECT TRUNC(7.53635, 2) FROM DUAL;


TRUNC(7.53635,2)
----------------
7.53

3. DATE SINGLE ROW FUNCTIONS:

. Using arithmetic operators:


SQL> SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKS FROM employees WHERE
department_id = 90;
OUTPUT:
LAST_NAME WEEKS
--------------------------
brindha 17.24888
rani 13.44442

. MONTHS_BETWEEN()
Purpose:
Number of months between two dates
SQL> select MONTHS_BETWEEN ('01-SEP-95','11-JAN-94') from sample1;
OUTPUT:
MONTHS_BETWEEN('01-SEP-95','11-JAN-94')
---------------------------------------
19.6774194

. ADD_MONTHS():
Purpose:
Add calendar months to date
SQL> SELECT ADD_MONTHS ('11-JAN-94',6) FROM SAMPLE1;

ADD_MONTH
---------
11-JUL-94

. NEXT_DAY():
Purpose:
Next day of the date specified
SQL> SELECT NEXT_DAY ('01-SEP-95','FRIDAY') FROM SAMPLE1;
NEXT_DAY(
---------
08-SEP-95
. LAST_DAY():
Last day of the month
SQL> SELECT LAST_DAY('01-FEB-95') FROM SAMPLE1;

LAST_DAY(
---------
28-FEB-95

. ROUND():
Round date at month where sysdate is '12-aug-2023'
SQL> SELECT ROUND(SYSDATE,'MONTH') FROM DUAL;
ROUND(SYS
---------
01-AUG-23

Round date at year where sysdate is '12-aug-2023'


SQL> SELECT ROUND(SYSDATE,'year') FROM DUAL;
ROUND(SYS
---------
01-JAN-24

. TRUNC():
Truncate date at month and year where sysdate is '12-aug-2023'
SQL> SELECT trunc(SYSDATE,'month'), trunc(sysdate,'year') FROM DUAL;
TRUNC(SYS TRUNC(SYS
--------- ---------
01-AUG-23 01-JAN-23

RESULT:

Thus, Single Row functions were executed.

You might also like