10992exp 2
10992exp 2
PART A
(PART A : TO BE REFFERED BY STUDENTS)
Experiment no: - 2
Theory: -
JonathonTaylor
17 6
PatFay
17 MK_REP 5
Number Functions
- ROUND: rounds value to specified decimal
SELECT ROUND (45.923, 2), ROUND (45.923, 0)
,
ROUND (45.923, -
1) FROM DUAL;
ROUND(45.923,2) ROUND (45.923, 0) ROUND (45.923, -1)
45.92 46 50
DUAL is a dummy table
- TRUNC: truncates value to specified decimal
SELECT TRUNC (45.923, 2), TRUNC
(45.923),
TRUNC (45.923, -
2) FROM DUAL;
TRUNC(45.923 , 2) TRUNC (45.923) TRUNC(45.923,-2)
45.92 45 0
- MOD: returns remainder of division
SELECT last-name, salary, MOD (salary, 5000) FROM
employees
WHERE job_id = „SA_REP‟;
LAST_NAME SALARY MOD(SLARY, 5000)
Abel 1100 1000
Taylor 6600 3600
Grant 7000 2000
Date Functions
- MONTHS_BETWEEN: Number of months between two
dates MONTHS_BETWEEN („01-SEM-95‟, ‟11-JAN-94‟)
ANS: 19.6774194
-
- ADD_MONTHS: Add calendar months to
date ADD_MONTHS (‟11-JAN-94‟, 6)
ANS: ’11-Jul-94’
- NEXT_DAY: Next day of month
NEXT_DAY („01-SEP-95‟, „FRIDAY’)
ANS: ’08-SEP-95’
- LAST_DAY: Last day of the month
LAST_DAY (‟01-FEB-95‟)
ANS: ’28-FEB-95’
Conversion Functions
Data type conversion
- from number to character
TO_CHAR (number, „format_model‟)
- from character to number
TO_NUMBER (char [, „format_model‟])
- from character to date
TO_DATE (char, „format_model‟])
- from date to character
TO_CHAR (date, „format_model‟)
General Functions
These functions work with any data type and pertain to using nulls.
- NVL (expr1, expr2)
- NVL2 (expr1, expr2, expr3)
- NULLIF (expr1, expr2)
- COALESCE ( expr1, expr2, ….,
exprn) Others are Conditional Expressions:
- Use of IF-THEN-ELSE logic within a SQL statement
- Use two methods: CASE expression and DECODE function
Conclusion:
This practical covers topics:
- Selecting, restricting, and sorting data.
- Perform calculations on data using various functions.
PART B
(PART B: TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two hours of the practical. The soft copy
must be uploaded on the Blackboard or emailed to the concerned lab in charge faculties at the end of the
practical in case the there is no Black board access available)