SlideShare a Scribd company logo
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

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
SIVASHANKARIRAJAN
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
Atul Sehdev
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Dr Sukhpal Singh Gill
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
ammarbrohi
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
Arpita Patel
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
sandeep54552
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
Satya P. Joshi
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
 

What's hot (20)

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Linked list
Linked listLinked list
Linked list
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 

Similar to SQL BUILT-IN FUNCTION

Single row functions
Single row functionsSingle row functions
Single row functions
Balqees Al.Mubarak
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functionsVivek Singh
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEUnit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
Functions
FunctionsFunctions
Functions
Ankit Dubey
 
Oracle sql ppt2
Oracle sql ppt2Oracle sql ppt2
Oracle sql ppt2
Madhavendra Dutt
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
Syed Zaid Irshad
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
Achmad Solichin
 
Les03
Les03Les03
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
Raviteja Chowdary Adusumalli
 
SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)
Logan Palanisamy
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
Muhammad Hammad Waseem
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
Angel G Diaz
 
Sql functions
Sql functionsSql functions
Sql functions
G C Reddy Technologies
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3Umair Amjad
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10Syed Asrarali
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
Fatih Nayebi, Ph.D.
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
Nitesh Singh
 

Similar to SQL BUILT-IN FUNCTION (20)

Single row functions
Single row functionsSingle row functions
Single row functions
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEUnit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
 
Functions
FunctionsFunctions
Functions
 
Les03
Les03Les03
Les03
 
Oracle sql ppt2
Oracle sql ppt2Oracle sql ppt2
Oracle sql ppt2
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
 
Les03
Les03Les03
Les03
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
Unit3 C
Unit3 C Unit3 C
Unit3 C
 
SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
 
Sql functions
Sql functionsSql functions
Sql functions
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 

More from Arun Sial

Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
Arun Sial
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
Arun Sial
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
Arun Sial
 
Procedure and Function in PLSQL
Procedure and Function in PLSQLProcedure and Function in PLSQL
Procedure and Function in PLSQL
Arun Sial
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
Arun Sial
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
Arun Sial
 

More from Arun Sial (6)

Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
 
Procedure and Function in PLSQL
Procedure and Function in PLSQLProcedure and Function in PLSQL
Procedure and Function in PLSQL
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
 

Recently uploaded

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 

Recently uploaded (20)

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 

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************