EX2C
EX2C
PROCEDURE:
1. CHARACTER SINGLE ROW FUNCTIONS:
.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
. 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
. 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
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
. 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
. 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: