Download presentation
Presentation is loading. Please wait.
2
Computations Done on table data
None of the techniques used till now allows display of data from a after some arithmetic has been done it. Computations may include displaying employee salary from the Employee_Master table along with annual salary.
3
Arithmetic Operators + : Addition - : Subtraction / : Division
* : Multiplication ** : Exponentiation () : Enclosed Operation
4
Logical Operators The AND Operator :
Select * from persons where name=‘’ and address=‘’; The OR Operator : Select * from persons where name=‘’ or address=‘’;
5
Combining AND and OR Operator
EX : Select * from persons where (name=‘’ and address=‘’) OR (name=‘’ and address=‘’);
6
The NOT operator Ex: Select * from persons where NOT ( name=‘a’ OR name=‘b’); The oracle engine will not display rows from the persons table where the value of the field NAME is either a or b.
7
Range Searching In order to select data that is within a range of values the BETWEEN operator is use. The lower value must be coded first. The values in between the range must be linked with the keyword AND. Data types can not be mixed.
8
Example Select * from persons where TO_CHAR(DOB,’MM’) BETWEEN 01 AND 03; Display persons birth date between month 1 and 4 Select * from persons where To_CHAR(DOB,’MM) NOT BETWEEN 01 AND 04; Not Display persons Birth Date between 01 and 04
9
Pattern Matchning The use of LIKE Predicate
The LIKE predicate allows comparison of one string value to another string value. For Character Data Types : % : Allow to match any string of any length _ : Allow to match on a single character.
10
Example Select name from persons where name LIKE ‘a%’; Output : Name
Abc Aaa Select name from persons where name LIKE ‘_a%’; Bac aaa
11
Alias (another name of attribute)
Rename the default output column names with an alias, when requried Syntax SELECT <COLUMNNAME><ALIASNAME>, <COLUMNNAME><ALIASNAME> FROM <TABLENAME>; Example SELECT NAME “FIRSTNAME” FROM PERSONS; Output FIRSTNAME abc
12
The IN and NOT IN predicates
The arithmetic operator(=) compares a single value to another single value. Compared to a list of values then the IN predicate is used. The IN predicate helps reduce the need to use multiple OR conditions. Example: List the customer details of the customers named CHINTAN, SANJAY AND VISHAL
13
SOLUTION SELECT FNAME,LNAME, DOB “BIRTHDATE” FROM PERSONS WHERE FNAME IN (‘CHINTAN’,’SANJAY’,’VISHAL’); FNAME LANME BIRTHDATE CHINTAN SHAH 29-APR-90 SANJAY PATEL 12-JUN-92 VISHAL 22-OCT-90
14
NOT IN The NOT IN predicate is the opposite of the IN predicate.
This will select all the rows where values do not match the values in the list. Example:- List the customer details of the customer other than CHINTAN,SANJAY AND VISHAL
15
SOLUTION SELECT FNAME,LNAME,DOB “BIRTHDATE” FROM PERSONS WHERE FNAME NOT IN(‘CHINTAN’,’SANJAY’,’VISHAL’); OUTPUT FNAME LANME BIRTHDATE NITIN PANDYA 29-APR-90 HETAL SHAH 12-JUN-92 KHUSHBU GANDHI 22-OCT-90 MUKESH GANGDIA 18-NOV-70 SAURIN PARIKH 22-FEB-80
16
ORACLE FUNCTION Oracle functions serve the purpose of manipulating data items and returning a result. Function are also capable of accepting user- supplied variables or constants and operation on them. Such variables or constants are called an arguments. Any number of arguments (or no arguments) can be passed to a function.
17
Assume table structure with data
DUAL table is already in built table in ORACLE. ACCOUNT TABLE ID NAME ACCNO BALANCE DESCRIPTION 1 CHINTAN 0001 25000 SAVINGS 2 SANJAY 0002 20000 CURRENT 3 NITIN 0003 18300 FD 4 KHUSHBU 0004 30000 SALARY 5 HETAL 0005 24000 DEMAT
18
Aggregate function AVG(AVERAGE): - Returns an average value of ‘n’.
Ignoring null value in a column. Syntax: - AVG(COLUMNNAME) Example: - SELECT AVG(BALANCE) “AVERAGE BALANCE” FROM ACCOUNT;
19
OUTPUT AVERAGE BALANCE 23460
20
Min and max MIN: - Returns a minimum value of expr. Syntax: -
MIN(COLUMNNAME) EXAMPLE: - SELECT MIN(BALANCE) “MINIMUM BALANCE” FROM ACCOUNT;
21
MIN AND MAX OUTPUT MINUMUM BALANCE 18300
MAX:- Returns the maximum value of expr. Syntax: - MAX(COUMNNAME) Example SELECT MAX(BALANCE) “MAXIMUM BALANCE” FROM PERSONS; MAXIMUM BALANCE 30000
22
COUNT COUNT(expr): Returns the number of rows where expr is not null.
Syntax: - COUNT(COLUMNAME) Example: - SELECT COUNT(ACCNO) “NO OF ACCOUNT” FROM ACCOUNT; Output: NO OF ACCOUNT 5
23
SUM SUM: - Return the sum of values. Syntax: - SUM(COLUMNNAME)
Example: - SELECT SUM(BALANCE) “TOTAL BALANCE” FROM ACCOUNT; Output: - TOTAL BALANCE 117300
24
Numeric function ABS(ABSOLUTE): - Returns the absolute value of ‘n’.
Syntax: - ABS(N) EXAMPLE
25
power POWER: - Returns m raised to the nth power. n must be an integer, else an error is returned. Syntax: POWER(M,N) EXAMPLE:-
26
ROUND ROUND: - returns n, rounded to m places to the right of a decimal point. If m is omitted, n is rounded to 0 places. m can be negative to round off digits to the left to of the decimal point. m must be an integer. Syntax: - ROUND(n,[m])
27
ROUND EXAMPLE
28
SQRT FUNCTION SQRT: - Returns square root of n. if n<0, NULL, SQRT returns real result. Syntax: - SQRT(n) Example: -
29
GREATEST FUNCTION GREATEST: - Returns the greatest value in a list of expression. Syntax: - GREATEST(expr1,expr2,…expn_n) Where expr1, expr2 are expression that are evaluated by the greatest function. Example:
30
Least function Same as GREATEST function but we will get least value.
Same Syntax but we need to use LEAST FUNCTION instead of GREATEST FUNCTION.
31
MOD FUNCTION MOD : - Returns the remainder of a first number divided by second number passed a parameter. If the second number is zero, the result is the same as first number. Syntax: - MOD(m,n)
32
MOD EXAMPLE
33
String function LOWER: - Returns char, with all letters in lowercase.
Syntax: - LOWER(char) Example :-
34
Initcap function INITCAP: - Returns a string with the first letter of each word in upper case. Syntax: - INITCAP(char) Example: -
35
UPPER FUNCTION UPPER: - Returns char, with all letters forced to uppercase. Syntax: - UPPER(char) Example: -
36
SUBSTR FUNCTION SUBSTR: - Returns a portion of characters, beginning at character m, and going up to character n. if n is omitted, the result returned is up to last character in the string. The first position of char is 1. Syntax: - SUBSTR(<STRING>,<START_POISTION>,<LENGTH>) Where STRING is the source string. START_POISTION is the position for extraction. The first position in the string is always 1. LENGTH is number of characters to extract
37
Substr example
38
Length function LENGTH: - Returns the length of a word. Syntax: -
LENGTH(word) Example: -
39
LTRIM FUNCTION LTRIM: - Removes character from the left of char with initial characters removed upto the first character not in set. Syntax: - LTRIM(char[,set]) Example: -
40
Question
41
TRIM FUNCTION TRIM:- Removes all specified characters either from the beginning or the ending of a string. Syntax:- TRIM([leading|trailing|both[<trim_character> from ]] <string1>) Leading:- remove trim_string from the front of string1. Trailing: - remove trim_string from the front and end of string1. Both- remove trim_string from and end of string1
42
CONVERSION FUNCTION TO_CHAR(number conversion): - converts a values of NUMBER datatype to a character datatype, using the optional format string. To accept a number(n) and a numeric format(fmt) in which the number has to appear. If fmt is omitted, n is converted to a char value exactly long enough to hold all significant digits. Syntax: - TO_CHAR(n[,fmt])
43
Example to_char(number conversation)
44
To_char(date conversation)
TO_CHAR: - Converts a value of a DATE datatype to CHAR value. TO_CHAR() accepts a data, as well as the format(fmt) in which the date has to appear. Fmt must in date format. If fmt is omitted, the date is converted to a character value using the default date format . What is default format? Syntax: - TO_CHAR(date[,fmt])
45
Example of to_char
46
DATE CONVERSION FUNCTION
TO_DATE: - Converts a character field to a date field. Syntax: - TO_DATE(char[,fmt]) Example:
47
DATE FUNTION ADD_MONTHS :- Returns date after adding the number of months specified in the function. Syntax: - ADD_MONTHS(d,n)
48
ADD_MONTH EXAMPLE
49
LAST_DAY LAST_DAY : - Returns the last date of the month specified with the function. Syntax : LAST_DAY(d) Example:
50
MONTHS_BETWEEN MONTHS-BETWEEN: - Returns number of months between d1 and d2. Syntax: - MONTHS_BETWEEN(d1,d2) Example: -
51
Next-day NEXT_DAY: - Returns the date of first weekday named by char that is after the date named by date. Char must be a day of the week. Syntax: - NEXT_DAY(date,char)
52
NEXT_DAY FUNCTION
53
To_char The TO_CHAR function facilitates the retrieval of data in a format different from the default format. It can also extract a part of the date, i.e. the date, month or year from the date value and use it for sorting or grouping of data according to date, month and year.
54
Syntax TO_CHAR(<date value> [,<fmt>])
where date value stands for the date and fmt is the specified format in which date is to be displayed.
55
PROBLEM
56
TO_DATE TO_DATE converts a char value into a date value.
It allows a user to insert data into a date column in any required format, by specifying the character value of the date to be inserted and its format
57
syntax TO_DATE(<char value> [,<fmt>])
Where char value stands for the value to be inserted in the date column, and fmt is date format in which the ‘char value’ is specified
58
EXAMPLE
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.