SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Prepared By JAVATECH Search us in the World
FUNCTION AND SET OPERATOR IN DBMS
Function:
Perform calculation on Data
Manipulate output for group of rows
Used Formats for display date & time
Function: Always takes argument and returns value.
Function 2 types
1. Single row function: Return one result per row
2. Multiple rows function or Group Function: Return one result per set of rows
Single Row Function
1. Character Fuction
2. Number Function
3. Date Function
4. Conversion Function
5. General Function
Group Function
1. Sum
2. Min
3. Max
4. Avg
5. Count
Single row function
Argument can be
1. User supplied constant E.g ‘arun’, 800
2. Variable E.g. name
3. Column name mark, grade
4. Expression E.g. fname || mark
Syntax using single row function
Select fun_name(argument) from dual;
Single-Row Functions (continued)
This lesson covers the following single-row functions:
• Character functions: accept character input and can return both character and number values.
• Number functions: Accept numeric input and return numeric values
• Date functions: Operate on values of the DATE data type (All date functions return a value
of DATE data type except the MONTHS_BETWEEN function, which returns a number.)
• Conversion functions: Convert a value from one data type to another
• General functions:
- NVL
- NVL2
- NULLIF
- COALESCE
- CASE
- DECODE
Character function two types
Case manipulation function
Lower
Upper
Initcap
Character Manipulation Function
Concat
Substr
Length
Instr
Lpad
Rpad
Trim
Replace, Ascii->returns ascii value of character , Chr-> returns the character value of a integer
Lower(str) Converts alpha character values to lowercase
Upper(str) Converts alpha character values to uppercase
Initcap(str) Converts alpha character values to uppercase for the first
letter of each word; all other letters in lowercase
Concat(str1,str2) Concatenates the first character value to the second character value; equivalent to
concatenation operator (||)
Substr(str,m,n) Returns specified characters from character value starting at character position m, n
characters long (If m is negative, the count starts from the end of the character
value. If n is omitted, all characters to the end of the string are returned.)
Length(str) Returns the number of characters in the expression
Lpad(col,n,str) Pads the character value right-justified to a total width of n character positions
Rpad(col,n,str) Pads the character value left-justified to a total width of n character positions
Trim(str from col) Enables you to trim heading or trailing characters (or both) from a character string.
Replace(col,sea,rep) Searches a text expression for a character string and, if found, replaces it with a
specified replacement string
Instr(col,text,START,OCCUR) Return the position of text from constant or column value. You can provide START
position. And OCCUR find no of occurence.
SELECT ASCII(‘A’) OUTPUT:65 FUNCTION AND OUTPUT SELECT CHR(97) OUTPUT: a
INITCAP(‘ARUN KUMAR’) OUTPUT: Arun Kumar
CONCAT(‘KIIT’, ‘UNIVERSITY’) KIITUNIVERSITY
SUBSTR(‘HELLO’,2,2) EL
LENGTH(‘KIIT’) 4
INSTR(‘JAVATECH 123’,’V’) 3
LPAD(‘ABC’,10,’*’) *******ABC
RPAD(‘ABC’,10,’*’) ABC*******
REPLACE(‘JACK’,’J’,’B’ BACK
TRIM(‘K’, FROM ‘KHELLO’) HELLO
Number function
Round function
Trunc function
Mod function
Sqrt function, power(2,5)
ROUND FUNCTION
ROUND(45.923,2) ROUND(45.923) ROUND(45.923,-1)
45.92 46 50
Rules
1. ROUND(45.923,2): after decimal it moves to 3rd digit (here is 3). Then round the value 3. It can’t
round because it is less than 5. So answer is 45.92. if it is 45.926 then 6 value will be rounded. Then
move to next vaue of two digit number 92 is 93. Result 45.93.
2. ROUND(45.923): After decimal it takes by default next digit. Next digit is 9 means greater than 5.
Then it will be rounded next. Then left side number will be incremented. Result 46. We write
ROUND(45.233) after decimal next digit is 2 it is less than 5 then it can’t be rounded. Then left value
remain same. Result 45.
3. ROUND(45.923,-1): Negative means it rounded before decimal. -1 means it rounded 5 value. Before
decimal first digit is 5.It move to next because it is equaly to 5. After 45 next round value is 50.
ROUND(44.233,-1) 4 is less than 5 so it will can’t round. Then value decrese 44 to 40. Result 40.
ROUND(944,233,-2) 944 can’t be round then value will be back of two digit no RESULT 900.
ROUND(944,233,-1) 44 can’t be round RESULT 40. And final result is 940.
TRUNC FUNCTION
TRUNC(45.923,2) TRUNC(45.923,0) TRUNC(45.923,-1)
45.92 45 40
TRUNC and ROUND both are same. But in third column TRUNC(45.923,-1). Here when we trunc 5 it will back to 0
means result is 40. Always it takes base value. 45 base value is 40.
SQRT FUNCTION
SELECT SQRT(4) FROM DUAL;
MOD FUNCTION RETURNS REMINDER
MOD(M,N) M IS DIVIDED BY N
SELECT MOD(5,2) FROM DUAL
DATE FUNCTION : All date function returns date except MONTHS_BETWEEN, which returns numeric
value.
1. MONTHS_BETWEEN- Returns the month difference between two dates
2. ADD_MONTHS- Add months to specific date
3. NEXT_DAY-Returns the next day of specified date
4. LAST_DAY- Returns the last day of specified month of given date
5. EXTRACT – Extract value from a specific date.
SYSDATE KEYWORD
It returns both current date and time of system
SELECT SYSDATE FROM DUAL;
CONVERSION FUNCTION
CONVERSION function is used to convert value from one data type to another data type. There are two
types of conversion function. 1. Implicit conversion 2. Explicit conversion.
Implicit conversion. It is automatically conversion by oracle server. But user needs to give the valid
constant or valid column expression.
Date -> conversion to Character
Character -> conversion to Date
E.g
SELECT * FROM STUD WHERE DOB < ’14-MAR-1995’;
In above you can see DOB datatype is date. But ’14-MAR-1995’ is character. It can be compared with
each other.
Number-> conversion to Character
Character-> conversion to Number
E.g.
SELECT * FROM STUDENT WHERE MARK<’75’;
In above example we compare MARK with 75. MARK datatype is number and 75, i specified in
character with double quotation.
EXPLICIT CONVERSION
USER NEED TO EXPLICIT CASTE. FOR THIS THERE ARE SOME FUNCTIONS
TO_NUMBER(CHARACTER, FORMAT_MODEL)
TO_DATE(CHARACTER,FORMAT_MODEL)
TO_CHAR(NUMBER|DATE,FORMAT_MODEL)
FORMAT_MODEL
1. Must be enclosed with single quotation
2. It is case sensitive
3. Format should be valid
DATE FUNCTION WITH OUTPUT.
MONTHS_BETWEEN('01-SEP-95','11-JAN-94') 19.6774194
ADD_MONTHS ('11-JAN-94',6) '11-JUL-94'
NEXT_DAY ('01-SEP-95','FRIDAY') '08-SEP-95'
LAST_DAY ('01-FEB-95') '28-FEB-95'
Extract(Month|DAY|YEAR from sysdate) 2
extract(month from to_date('12-jan-2018','DD-MON-YY')) 2
ROUND(’25-JUL-03’,'MONTH') ‘01-AUG-03’
ROUND(’25-JUL-03’ ,'YEAR') ‘01-JAN-04’
TRUNC(’25-JUL-03’ ,'MONTH') ‘01-JUL-03’
TRUNC(’25-JUL-03’ ,'YEAR') ‘01-JAN-03’
ELEMENTS OF DATE FORMAT MODEL
ELEMENT KEYWORD RESULT SYSDATE : 18-FEB-2018
YYYY Full year in numbers OUTPUT:2018
YEAR Year spelled out (in English) OUTPUT:TWENTY EIGHTEEN
MM Two-digit value for month OUTPUT:2
MONTH Full name of the month OUTPUT:FEBRUARY
MON MON OUTPUT:FEB
DY Three-letter abbreviation of the day of the week OUTPUT:SUN
DAY Full name of the day of the week OUTPUT:SUNDAY
DD Numeric day of the month OUTPUT:18 (DAY)
YY Two-digit value for year OUTOUT:18
ELEMENT DESCRIPTION EXAMPLE RESULT
9 Numeric position (number of 9s determine display Width) 999999 --1234
0 Display zero left side 099999 001234
$ Floating dollar sign $999999 $1234
EXAMPLE OF TO_CHAR FUNCTION FROM DATE TO VARCHAR OUTPUT
TO_CHAR(SYSDATE,’MM/YY’) 02/18
TO_CHAR(SYSDATE,’DD “OF” MONTH’) 18 OF FEBRUARY
TO_CHAR(SYSDATE,’DD MONTH YEAR’) 18 FEBRUARY TWENTY EIGHTEEN
EXAMPLE OF TO_CHAR FUNCTION FROM NUMBER TO VARCHAR OUTPUT
TO_CHAR(125,999999) ---125
TO_CHAR(125,099999) 000125
TO_CHAR(125,’$999) $125
EXAMPLE OF TO_DATE FUNCTION FROM CHAR TO DATE OUTPUT
TO_DATE('01-Jan-90','DD-Mon-RR') 01-JAN-90
TO_DATE('May 24, 1999', 'Month
DD, YYYY');
24-may-1999
NESTING FUNCTION
UPPER(CONCAT(‘aa’,’bb’))
GROUP FUNCTION OR AGGREGATE FUNCTION PAGE-7
1) MAX 2) MIN 3) COUNT 4) AVG 5) SUM
SELECT COUNT(*) FROM STUDENT; COUNT NO OF ROWS
SELECT MAX(SALARY) FROM EMPLOYEE; FIND MAXIMUM SALARY FROM EMPLOYEE TABLE.
GENERAL FUNCTION
This function can work on any data type. And it avoids the null values from list.
• NVL (expr1, expr2)
Converts a null value to an actual value.
Data types must match:
– NVL(commission_pct,0)
– NVL(hire_date,'01-JAN-97')
– NVL(job_id,'No Job Yet')
• NVL2 (expr1, expr2, expr3)
If expr1 is not null, NVL2 returns expr2. If expr1 is null, NVL2 returns expr3. The argument expr1 can
have any data type.
• NULLIF (expr1, expr2)
Compares two expressions and returns null if they are equal; returns the first expression if they are
not equal
• COALESCE (expr1, expr2, ..., exprn)
Returns the first non-null expression in the expression list
The advantage of the COALESCE function over the NVL function is that the COALESCE function can
take multiple alternate values.
If the first expression is not null, the COALESCE function returns that expression; otherwise, it does a
COALESCE of the remaining expressions.
CAN PERFORM IF ELSE LOGIC BY USING CASE & DECODE FUNCTIONS.
SYNTAX
CASE expr WHEN comparison_expr1 THEN return_expr1
[WHEN comparison_expr2 THEN return_expr2
WHEN comparison_exprn THEN return_exprn
ELSE else_expr]
END
SELECT last_name, job_id, salary,
CASE job_id WHEN 'IT_PROG' THEN 1.10*salary
WHEN 'ST_CLERK' THEN 1.15*salary
WHEN 'SA_REP' THEN 1.20*salary
ELSE salary END "REVISED_SALARY" FROM employees;
DECODE FUNCTION IS SAME AS CASE. IN DECODE FUNCTION WE SPECIFY DEFAULT VALUE. IF DEFAULT VALUE
NOT GIVEN THEN NULL VALUE RETURN.
SELECT last_name, job_id, salary,DECODE(job_id, 'IT_PROG', 1.10*salary,
'ST_CLERK', 1.15*salary,
'SA_REP', 1.20*salary,
salary) REVISED_SALARY FROM employees;
DECODE(job_id, 'IT_PROG', 1.10*salary,
JOB_ID IS COLUMN
IT_PROG IS CONDITION
RESULT RETURN 1.10*SALARY
SALARY IS DEFALUT VALUE
SET OPERATOR
SET OPERATOR IS USED TO COMBILE MULTIPLE QUERY INTO Single one.
UNION -> OPERATOR RETURNS RESULT FROM BOTH QUERY AFTER ELIMINATING DUPLICATIONS
UNION ALL->OPERATOR RETURNS RESULT FROM BOTH QUERIES, INCLUDING ALL DUPLICATIONS.
INTERSECT ->OPERATOR RETURNS QUERIES THOSE ARE COMMON TO BOTH TABLE.
MINUS->RETURNS ALL DISTICT ROWS SELECTED BY THE FIRST QUERY NOT BY THE SECOND QUERY.
*************THANKING YOU*********
.............................................. LAB ASSIGNMET............................………….
BIGBAZAR TABLE Prepared By JAVATECH Search us in the World
ITEM_NAME ITEM_NO ITEM_QTY ITEM_PRICE ITEM_MFG_DATE ITEM_EXP_DATE ORDER_NO
COL101 20 75.95 12-JAN-2003 27-APR-2017 ORD1001
LUX_SHOAP LU102 15 25.40 19-JUL-2001 30-MAR-2019 ORD1029
DABUR_HONEY DAB103 40 120.70 20-MAR-2015 12-JUN-2020 ORD1010
TATA_TEA TAT104 50 98.50 15-SEP-2008 ORD1035
SURF_EXCEL SUR105 NULL 285.60 28-AUG-2015 20-NOV-2020 ORD1030
DETTOL_HANDWASH DET106 42 45.50 28-FEB-2013 23-AUG-2018 ORD1020
ASHRIBAD_ATTA ASH107 20 170.45 28-JUN-2007 20-SEP-2019 ORD1040
AMU108 28 175.20 03-MAY-2005 06-AUG-2017 ORD1015
HORLICKS NULL 286.90 29-OCT-2012 30-JUN-2018 ORD1028
ARIEL_MATIC ARL110 30 230.80 14-NON-2016 ORD1032
PONDS_POWER PON111 50 85.90 25-MAY-2011 30-APR-2020 ORD1044
TOMATO_KATCHUP TOM112 30 35 30-DEC-2014 09-SEP-2018
PATANJALI_BISCUIT PAT113 39 25 01-JAN-2016 29-JUN-2018 ORD1061
KISSAN_JAM KIS114 NULL 90 22-FEB-2015 30-OCT-2016 ORD1037
COLGATE_PASTE, AMUL_SPRAY, HOR109, ORD1055, 19-AUG-2016, 28-NOV-2019
1. Waq to display the maximum item quantity from table bigbazar.
2. Waq to display the item_name,item_price those expire date in month of JUN.
3. Waq to display the item_name, item_price those expire date less than system date.
4. Waq to display the item_name,item_no,item_price & virtual column ‘duration’ which display how
many months difference between item_mfg_date & item_exp_date.
5. Waq to display mfg date with round function.
6. Waq to display all columns from all rows from table and item_price should display with $sign.
7. Waq to display item_name,item_no,item_price, and the day only display from item_mfg_date &
item_exp_date from table not full date.
8. Waq to display item_name,item_no,item_price with rounded,item_mfg_date and item_exp_date.
9. Waq to display table all rows by converting NULL value into 0 in ITEM_QTY .
10. Waq to display table all rows and if item_exp_date null then it return sysdate else display their
existing date.
11. Waq to display only rows those are expires and replace their expire date to be system date. (No
update command).
12. Waq to display all rows item if their item_qty is 50 then it should return null. Otherwise it display
their original item_qty.
13. We can find product by their item_name, item_no and order_no. Now display item_desc (virtual
column), item_qty,item_price,item_mfg_date,item_exp_date from table. Note [ item_desc column
display item from any of one column item_name or item_no or order_no.
14. Waq to display only value of one column from item_name or item_no or order_no along with
item_qty, item_price, item_mfg_date, item_exp_date from table.
15. Waq to display all items from table and calculate 0.35 rebate on order of exact qty of 50. 0.25 rebate
on order of exact qty 30. 0.15 rebate on order of exact qty 20. Display all data along with rebate
amount. Use CASE expression.
16. Waq to display all items from table and calculate 0.35 rebate on order of exact qty of 50. 0.25 rebate
on order of exact qty 30. 0.15 rebate on order of qty 20. Display all data along with rebate amount.
Use DECODE function.
WAIT OUR NEXT SLIDE ABOUT DATABASE OBJECT, SUB-QUERY AND JOIN COMMAND.
JOIN :- IS USED TO DISPLAY DATA FROM MORE THAN ONE TABLE.
JOINS TYPE
1. EQUI JOIN OR SIMPLE JOIN OR INNER JOIN ORACLE 8i OR PRIOR
2. CROSS JOIN
3. NON-EQUI JOIN
4. OUTER JOIN
5. SELF JOIN
6. NATURAL JOIN ORACLE 9i VERSION OR AFTER
7. CARTESIAN JOIN
8. JOIN WITH USING CLAUSE
9. JOIN WITH ON CLAUSE
10. OUTER JOIN
FOLLOW & LIKE OUR FACEBOOK PAGE “JAVATECH 123” YOU CAN GET SOLUTION
Prepared By JAVATECH Search us from in The World
**************BEST OF LUCK************

More Related Content

What's hot (20)

PPTX
Templates in c++
ThamizhselviKrishnam
 
PPT
6. Integrity and Security in DBMS
koolkampus
 
PPTX
Sql subquery
Raveena Thakur
 
PPTX
Sql(structured query language)
Ishucs
 
PPT
Week 3 Classification of Database Management Systems & Data Modeling
oudesign
 
PPTX
Solving recurrences
Megha V
 
PPTX
Types Of Keys in DBMS
PadamNepal1
 
PPTX
SQL Commands
Sachidananda M H
 
PPTX
DATABASE CONSTRAINTS
sunanditaAnand
 
PPT
Sql join
Vikas Gupta
 
PPTX
SQL Joins.pptx
Ankit Rai
 
PDF
Java threads
Prabhakaran V M
 
PPTX
Ppt on this and super keyword
tanu_jaswal
 
PDF
Normalization in DBMS
Hitesh Mohapatra
 
PPTX
Binary search
AparnaKumari31
 
PPTX
Tree Traversal
Md. Israil Fakir
 
PPTX
SQL commands
GirdharRatne
 
PPTX
5. stored procedure and functions
Amrit Kaur
 
PPT
Pattern matching
shravs_188
 
PPSX
Break and continue
Frijo Francis
 
Templates in c++
ThamizhselviKrishnam
 
6. Integrity and Security in DBMS
koolkampus
 
Sql subquery
Raveena Thakur
 
Sql(structured query language)
Ishucs
 
Week 3 Classification of Database Management Systems & Data Modeling
oudesign
 
Solving recurrences
Megha V
 
Types Of Keys in DBMS
PadamNepal1
 
SQL Commands
Sachidananda M H
 
DATABASE CONSTRAINTS
sunanditaAnand
 
Sql join
Vikas Gupta
 
SQL Joins.pptx
Ankit Rai
 
Java threads
Prabhakaran V M
 
Ppt on this and super keyword
tanu_jaswal
 
Normalization in DBMS
Hitesh Mohapatra
 
Binary search
AparnaKumari31
 
Tree Traversal
Md. Israil Fakir
 
SQL commands
GirdharRatne
 
5. stored procedure and functions
Amrit Kaur
 
Pattern matching
shravs_188
 
Break and continue
Frijo Francis
 

Similar to SQL BUILT-IN FUNCTION (20)

PPTX
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
PPT
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
PPT
Les03
Sudharsan S
 
PPT
Les03
arnold 7490
 
PPT
Les03
Vijay Kumar
 
PPT
Using single row functions to customize output
Syed Zaid Irshad
 
PPT
Single row functions
Balqees Al.Mubarak
 
PPT
e computer notes - Single row functions
ecomputernotes
 
PDF
An Illustrative Approach to Use SQL Functions: A Review
IJEACS
 
PPT
Day1Structured_Query_Lang3For PL SQL Notes.ppt
consravs
 
PPT
Sql 3
Nargis Ehsan
 
PPT
Single-Row Functions in orcale Data base
Salman Memon
 
PDF
Basic Sql Handouts
jhe04
 
PPT
SQL WORKSHOP::Lecture 3
Umair Amjad
 
PPT
Oracle sql ppt2
Madhavendra Dutt
 
PDF
COIS 420 - Practice 03
Angel G Diaz
 
PPTX
Les03.pptx
NishaTariq1
 
PDF
Sql functions
Ankit Dubey
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
Using single row functions to customize output
Syed Zaid Irshad
 
Single row functions
Balqees Al.Mubarak
 
e computer notes - Single row functions
ecomputernotes
 
An Illustrative Approach to Use SQL Functions: A Review
IJEACS
 
Day1Structured_Query_Lang3For PL SQL Notes.ppt
consravs
 
Single-Row Functions in orcale Data base
Salman Memon
 
Basic Sql Handouts
jhe04
 
SQL WORKSHOP::Lecture 3
Umair Amjad
 
Oracle sql ppt2
Madhavendra Dutt
 
COIS 420 - Practice 03
Angel G Diaz
 
Les03.pptx
NishaTariq1
 
Sql functions
Ankit Dubey
 
Ad

More from Arun Sial (6)

PDF
Triggers in plsql
Arun Sial
 
PDF
PLSQL CURSOR
Arun Sial
 
PDF
Exception handling in plsql
Arun Sial
 
PDF
Procedure and Function in PLSQL
Arun Sial
 
PDF
PLSQL Note
Arun Sial
 
DOCX
Database object, sub query, Join Commands & Lab Assignment
Arun Sial
 
Triggers in plsql
Arun Sial
 
PLSQL CURSOR
Arun Sial
 
Exception handling in plsql
Arun Sial
 
Procedure and Function in PLSQL
Arun Sial
 
PLSQL Note
Arun Sial
 
Database object, sub query, Join Commands & Lab Assignment
Arun Sial
 
Ad

Recently uploaded (20)

PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Human Resources Information System (HRIS)
Amity University, Patna
 

SQL BUILT-IN FUNCTION

  • 1. Prepared By JAVATECH Search us in the World FUNCTION AND SET OPERATOR IN DBMS Function: Perform calculation on Data Manipulate output for group of rows Used Formats for display date & time Function: Always takes argument and returns value. Function 2 types 1. Single row function: Return one result per row 2. Multiple rows function or Group Function: Return one result per set of rows Single Row Function 1. Character Fuction 2. Number Function 3. Date Function 4. Conversion Function 5. General Function Group Function 1. Sum 2. Min 3. Max 4. Avg 5. Count Single row function Argument can be 1. User supplied constant E.g ‘arun’, 800 2. Variable E.g. name 3. Column name mark, grade 4. Expression E.g. fname || mark Syntax using single row function Select fun_name(argument) from dual;
  • 2. Single-Row Functions (continued) This lesson covers the following single-row functions: • Character functions: accept character input and can return both character and number values. • Number functions: Accept numeric input and return numeric values • Date functions: Operate on values of the DATE data type (All date functions return a value of DATE data type except the MONTHS_BETWEEN function, which returns a number.) • Conversion functions: Convert a value from one data type to another • General functions: - NVL - NVL2 - NULLIF - COALESCE - CASE - DECODE Character function two types Case manipulation function Lower Upper Initcap Character Manipulation Function Concat Substr
  • 3. Length Instr Lpad Rpad Trim Replace, Ascii->returns ascii value of character , Chr-> returns the character value of a integer Lower(str) Converts alpha character values to lowercase Upper(str) Converts alpha character values to uppercase Initcap(str) Converts alpha character values to uppercase for the first letter of each word; all other letters in lowercase Concat(str1,str2) Concatenates the first character value to the second character value; equivalent to concatenation operator (||) Substr(str,m,n) Returns specified characters from character value starting at character position m, n characters long (If m is negative, the count starts from the end of the character value. If n is omitted, all characters to the end of the string are returned.) Length(str) Returns the number of characters in the expression Lpad(col,n,str) Pads the character value right-justified to a total width of n character positions Rpad(col,n,str) Pads the character value left-justified to a total width of n character positions Trim(str from col) Enables you to trim heading or trailing characters (or both) from a character string. Replace(col,sea,rep) Searches a text expression for a character string and, if found, replaces it with a specified replacement string Instr(col,text,START,OCCUR) Return the position of text from constant or column value. You can provide START position. And OCCUR find no of occurence. SELECT ASCII(‘A’) OUTPUT:65 FUNCTION AND OUTPUT SELECT CHR(97) OUTPUT: a INITCAP(‘ARUN KUMAR’) OUTPUT: Arun Kumar CONCAT(‘KIIT’, ‘UNIVERSITY’) KIITUNIVERSITY SUBSTR(‘HELLO’,2,2) EL LENGTH(‘KIIT’) 4 INSTR(‘JAVATECH 123’,’V’) 3 LPAD(‘ABC’,10,’*’) *******ABC RPAD(‘ABC’,10,’*’) ABC******* REPLACE(‘JACK’,’J’,’B’ BACK TRIM(‘K’, FROM ‘KHELLO’) HELLO Number function Round function Trunc function Mod function Sqrt function, power(2,5)
  • 4. ROUND FUNCTION ROUND(45.923,2) ROUND(45.923) ROUND(45.923,-1) 45.92 46 50 Rules 1. ROUND(45.923,2): after decimal it moves to 3rd digit (here is 3). Then round the value 3. It can’t round because it is less than 5. So answer is 45.92. if it is 45.926 then 6 value will be rounded. Then move to next vaue of two digit number 92 is 93. Result 45.93. 2. ROUND(45.923): After decimal it takes by default next digit. Next digit is 9 means greater than 5. Then it will be rounded next. Then left side number will be incremented. Result 46. We write ROUND(45.233) after decimal next digit is 2 it is less than 5 then it can’t be rounded. Then left value remain same. Result 45. 3. ROUND(45.923,-1): Negative means it rounded before decimal. -1 means it rounded 5 value. Before decimal first digit is 5.It move to next because it is equaly to 5. After 45 next round value is 50. ROUND(44.233,-1) 4 is less than 5 so it will can’t round. Then value decrese 44 to 40. Result 40. ROUND(944,233,-2) 944 can’t be round then value will be back of two digit no RESULT 900. ROUND(944,233,-1) 44 can’t be round RESULT 40. And final result is 940. TRUNC FUNCTION TRUNC(45.923,2) TRUNC(45.923,0) TRUNC(45.923,-1) 45.92 45 40 TRUNC and ROUND both are same. But in third column TRUNC(45.923,-1). Here when we trunc 5 it will back to 0 means result is 40. Always it takes base value. 45 base value is 40. SQRT FUNCTION SELECT SQRT(4) FROM DUAL; MOD FUNCTION RETURNS REMINDER MOD(M,N) M IS DIVIDED BY N SELECT MOD(5,2) FROM DUAL DATE FUNCTION : All date function returns date except MONTHS_BETWEEN, which returns numeric value. 1. MONTHS_BETWEEN- Returns the month difference between two dates 2. ADD_MONTHS- Add months to specific date 3. NEXT_DAY-Returns the next day of specified date 4. LAST_DAY- Returns the last day of specified month of given date 5. EXTRACT – Extract value from a specific date. SYSDATE KEYWORD It returns both current date and time of system SELECT SYSDATE FROM DUAL;
  • 5. CONVERSION FUNCTION CONVERSION function is used to convert value from one data type to another data type. There are two types of conversion function. 1. Implicit conversion 2. Explicit conversion. Implicit conversion. It is automatically conversion by oracle server. But user needs to give the valid constant or valid column expression. Date -> conversion to Character Character -> conversion to Date E.g SELECT * FROM STUD WHERE DOB < ’14-MAR-1995’; In above you can see DOB datatype is date. But ’14-MAR-1995’ is character. It can be compared with each other. Number-> conversion to Character Character-> conversion to Number E.g. SELECT * FROM STUDENT WHERE MARK<’75’; In above example we compare MARK with 75. MARK datatype is number and 75, i specified in character with double quotation. EXPLICIT CONVERSION USER NEED TO EXPLICIT CASTE. FOR THIS THERE ARE SOME FUNCTIONS TO_NUMBER(CHARACTER, FORMAT_MODEL) TO_DATE(CHARACTER,FORMAT_MODEL) TO_CHAR(NUMBER|DATE,FORMAT_MODEL) FORMAT_MODEL 1. Must be enclosed with single quotation 2. It is case sensitive 3. Format should be valid DATE FUNCTION WITH OUTPUT. MONTHS_BETWEEN('01-SEP-95','11-JAN-94') 19.6774194 ADD_MONTHS ('11-JAN-94',6) '11-JUL-94' NEXT_DAY ('01-SEP-95','FRIDAY') '08-SEP-95' LAST_DAY ('01-FEB-95') '28-FEB-95' Extract(Month|DAY|YEAR from sysdate) 2 extract(month from to_date('12-jan-2018','DD-MON-YY')) 2 ROUND(’25-JUL-03’,'MONTH') ‘01-AUG-03’ ROUND(’25-JUL-03’ ,'YEAR') ‘01-JAN-04’ TRUNC(’25-JUL-03’ ,'MONTH') ‘01-JUL-03’ TRUNC(’25-JUL-03’ ,'YEAR') ‘01-JAN-03’
  • 6. ELEMENTS OF DATE FORMAT MODEL ELEMENT KEYWORD RESULT SYSDATE : 18-FEB-2018 YYYY Full year in numbers OUTPUT:2018 YEAR Year spelled out (in English) OUTPUT:TWENTY EIGHTEEN MM Two-digit value for month OUTPUT:2 MONTH Full name of the month OUTPUT:FEBRUARY MON MON OUTPUT:FEB DY Three-letter abbreviation of the day of the week OUTPUT:SUN DAY Full name of the day of the week OUTPUT:SUNDAY DD Numeric day of the month OUTPUT:18 (DAY) YY Two-digit value for year OUTOUT:18 ELEMENT DESCRIPTION EXAMPLE RESULT 9 Numeric position (number of 9s determine display Width) 999999 --1234 0 Display zero left side 099999 001234 $ Floating dollar sign $999999 $1234 EXAMPLE OF TO_CHAR FUNCTION FROM DATE TO VARCHAR OUTPUT TO_CHAR(SYSDATE,’MM/YY’) 02/18 TO_CHAR(SYSDATE,’DD “OF” MONTH’) 18 OF FEBRUARY TO_CHAR(SYSDATE,’DD MONTH YEAR’) 18 FEBRUARY TWENTY EIGHTEEN EXAMPLE OF TO_CHAR FUNCTION FROM NUMBER TO VARCHAR OUTPUT TO_CHAR(125,999999) ---125 TO_CHAR(125,099999) 000125 TO_CHAR(125,’$999) $125 EXAMPLE OF TO_DATE FUNCTION FROM CHAR TO DATE OUTPUT TO_DATE('01-Jan-90','DD-Mon-RR') 01-JAN-90 TO_DATE('May 24, 1999', 'Month DD, YYYY'); 24-may-1999 NESTING FUNCTION UPPER(CONCAT(‘aa’,’bb’))
  • 7. GROUP FUNCTION OR AGGREGATE FUNCTION PAGE-7 1) MAX 2) MIN 3) COUNT 4) AVG 5) SUM SELECT COUNT(*) FROM STUDENT; COUNT NO OF ROWS SELECT MAX(SALARY) FROM EMPLOYEE; FIND MAXIMUM SALARY FROM EMPLOYEE TABLE. GENERAL FUNCTION This function can work on any data type. And it avoids the null values from list. • NVL (expr1, expr2) Converts a null value to an actual value. Data types must match: – NVL(commission_pct,0) – NVL(hire_date,'01-JAN-97') – NVL(job_id,'No Job Yet') • NVL2 (expr1, expr2, expr3) If expr1 is not null, NVL2 returns expr2. If expr1 is null, NVL2 returns expr3. The argument expr1 can have any data type. • NULLIF (expr1, expr2) Compares two expressions and returns null if they are equal; returns the first expression if they are not equal • COALESCE (expr1, expr2, ..., exprn) Returns the first non-null expression in the expression list The advantage of the COALESCE function over the NVL function is that the COALESCE function can take multiple alternate values. If the first expression is not null, the COALESCE function returns that expression; otherwise, it does a COALESCE of the remaining expressions. CAN PERFORM IF ELSE LOGIC BY USING CASE & DECODE FUNCTIONS. SYNTAX CASE expr WHEN comparison_expr1 THEN return_expr1 [WHEN comparison_expr2 THEN return_expr2 WHEN comparison_exprn THEN return_exprn ELSE else_expr] END SELECT last_name, job_id, salary, CASE job_id WHEN 'IT_PROG' THEN 1.10*salary WHEN 'ST_CLERK' THEN 1.15*salary WHEN 'SA_REP' THEN 1.20*salary ELSE salary END "REVISED_SALARY" FROM employees;
  • 8. DECODE FUNCTION IS SAME AS CASE. IN DECODE FUNCTION WE SPECIFY DEFAULT VALUE. IF DEFAULT VALUE NOT GIVEN THEN NULL VALUE RETURN. SELECT last_name, job_id, salary,DECODE(job_id, 'IT_PROG', 1.10*salary, 'ST_CLERK', 1.15*salary, 'SA_REP', 1.20*salary, salary) REVISED_SALARY FROM employees; DECODE(job_id, 'IT_PROG', 1.10*salary, JOB_ID IS COLUMN IT_PROG IS CONDITION RESULT RETURN 1.10*SALARY SALARY IS DEFALUT VALUE SET OPERATOR SET OPERATOR IS USED TO COMBILE MULTIPLE QUERY INTO Single one. UNION -> OPERATOR RETURNS RESULT FROM BOTH QUERY AFTER ELIMINATING DUPLICATIONS UNION ALL->OPERATOR RETURNS RESULT FROM BOTH QUERIES, INCLUDING ALL DUPLICATIONS. INTERSECT ->OPERATOR RETURNS QUERIES THOSE ARE COMMON TO BOTH TABLE. MINUS->RETURNS ALL DISTICT ROWS SELECTED BY THE FIRST QUERY NOT BY THE SECOND QUERY. *************THANKING YOU*********
  • 9. .............................................. LAB ASSIGNMET............................…………. BIGBAZAR TABLE Prepared By JAVATECH Search us in the World ITEM_NAME ITEM_NO ITEM_QTY ITEM_PRICE ITEM_MFG_DATE ITEM_EXP_DATE ORDER_NO COL101 20 75.95 12-JAN-2003 27-APR-2017 ORD1001 LUX_SHOAP LU102 15 25.40 19-JUL-2001 30-MAR-2019 ORD1029 DABUR_HONEY DAB103 40 120.70 20-MAR-2015 12-JUN-2020 ORD1010 TATA_TEA TAT104 50 98.50 15-SEP-2008 ORD1035 SURF_EXCEL SUR105 NULL 285.60 28-AUG-2015 20-NOV-2020 ORD1030 DETTOL_HANDWASH DET106 42 45.50 28-FEB-2013 23-AUG-2018 ORD1020 ASHRIBAD_ATTA ASH107 20 170.45 28-JUN-2007 20-SEP-2019 ORD1040 AMU108 28 175.20 03-MAY-2005 06-AUG-2017 ORD1015 HORLICKS NULL 286.90 29-OCT-2012 30-JUN-2018 ORD1028 ARIEL_MATIC ARL110 30 230.80 14-NON-2016 ORD1032 PONDS_POWER PON111 50 85.90 25-MAY-2011 30-APR-2020 ORD1044 TOMATO_KATCHUP TOM112 30 35 30-DEC-2014 09-SEP-2018 PATANJALI_BISCUIT PAT113 39 25 01-JAN-2016 29-JUN-2018 ORD1061 KISSAN_JAM KIS114 NULL 90 22-FEB-2015 30-OCT-2016 ORD1037 COLGATE_PASTE, AMUL_SPRAY, HOR109, ORD1055, 19-AUG-2016, 28-NOV-2019 1. Waq to display the maximum item quantity from table bigbazar. 2. Waq to display the item_name,item_price those expire date in month of JUN. 3. Waq to display the item_name, item_price those expire date less than system date. 4. Waq to display the item_name,item_no,item_price & virtual column ‘duration’ which display how many months difference between item_mfg_date & item_exp_date. 5. Waq to display mfg date with round function. 6. Waq to display all columns from all rows from table and item_price should display with $sign. 7. Waq to display item_name,item_no,item_price, and the day only display from item_mfg_date & item_exp_date from table not full date. 8. Waq to display item_name,item_no,item_price with rounded,item_mfg_date and item_exp_date. 9. Waq to display table all rows by converting NULL value into 0 in ITEM_QTY .
  • 10. 10. Waq to display table all rows and if item_exp_date null then it return sysdate else display their existing date. 11. Waq to display only rows those are expires and replace their expire date to be system date. (No update command). 12. Waq to display all rows item if their item_qty is 50 then it should return null. Otherwise it display their original item_qty. 13. We can find product by their item_name, item_no and order_no. Now display item_desc (virtual column), item_qty,item_price,item_mfg_date,item_exp_date from table. Note [ item_desc column display item from any of one column item_name or item_no or order_no. 14. Waq to display only value of one column from item_name or item_no or order_no along with item_qty, item_price, item_mfg_date, item_exp_date from table. 15. Waq to display all items from table and calculate 0.35 rebate on order of exact qty of 50. 0.25 rebate on order of exact qty 30. 0.15 rebate on order of exact qty 20. Display all data along with rebate amount. Use CASE expression. 16. Waq to display all items from table and calculate 0.35 rebate on order of exact qty of 50. 0.25 rebate on order of exact qty 30. 0.15 rebate on order of qty 20. Display all data along with rebate amount. Use DECODE function. WAIT OUR NEXT SLIDE ABOUT DATABASE OBJECT, SUB-QUERY AND JOIN COMMAND. JOIN :- IS USED TO DISPLAY DATA FROM MORE THAN ONE TABLE. JOINS TYPE 1. EQUI JOIN OR SIMPLE JOIN OR INNER JOIN ORACLE 8i OR PRIOR 2. CROSS JOIN 3. NON-EQUI JOIN 4. OUTER JOIN 5. SELF JOIN 6. NATURAL JOIN ORACLE 9i VERSION OR AFTER 7. CARTESIAN JOIN 8. JOIN WITH USING CLAUSE 9. JOIN WITH ON CLAUSE 10. OUTER JOIN FOLLOW & LIKE OUR FACEBOOK PAGE “JAVATECH 123” YOU CAN GET SOLUTION Prepared By JAVATECH Search us from in The World **************BEST OF LUCK************