Unit II
Unit II
RELATIONAL MODEL
Introduction to relational model
The principles of the relational model were first outlined by Dr. E. F. Codd in a June 1970
paper called "A Relational Model of Data for Large Shared Data Banks:' In this paper. Dr.
Codd proposed the relational model for database systems. The more popular models used
at that time were hierarchical and network, or even simple flat file data structures.
Relational database management systems (RDBMS) soon became very popular, especially
for their ease of use and flexibility in structure. In addition, a number of innovative
vendors, such as Oracle, supplemented the RDBMS \with a suite of powerful application
development and user products, providing a total solution.Earlier we saw how to convert
an unorganized text description of information requirements into a conceptual design, by
the use of ER diagrams. The advantage of ER diagrams is that they force you to identify
data requirements that are implicitly known, but not explicitly written down in the original
description. Here we will see how to convert this ER into a logical design (this will be
defined below) of a relational database. The logical model is also called a Relational
Model.
Relational Model Concepts
We shall represent a relation as a table with columns and rows. Each column of the table
has a name, or attribute. Each row is called a tuple.
Relation Instance, r( R): a set of tuples; thus, r( R) = { t1, t2, t3, …, tm}
Properties of relations
Properties of database relations are:
relation name is distinct from all other relations
each cell of relation contains exactly one atomic (single) value
each attribute has a distinct name
values of an attribute are all from the same domain
order of attributes has no significance
each tuple is distinct; there are no duplicate tuples
order of tuples has no significance, theoretically.
Relational keys
There are two kinds of keys in relations. The first are identifying keys: the
primary key is the main concept, while two other keys – super key and
candidate key – are related concepts. The second kind is the foreign key.
Identity Keys
Super keys
Primary Key
The primary key of a relation is a candidate key especially selected to be the key for the
relation. In other words, it is a choice, and there can be only one candidate key designated to
be the primary key.
Relationship between identity keys
The relationship between keys:
Superkey Candidate Key Primary Key
Foreign keys
The attribute(s) within one relation that matches a candidate key of another relation. A
relation may have several foreign keys, associated with different target relations.Foreign keys
allow users to link information in one relation to information in another relation. Without
FKs, a database would be a collection of unrelated tables.
Integrity Constraints
Each relational schema must satisfy the following four types of constraints.
a.Domain constraints
Each attribute Ai must be an atomic value from dom( Ai) for that attribute. The attribute,
Name in the example is a BAD DESIGN (because sometimes we may want to search a person
by only using their last name.
b.Key Constraints
Superkey of R: A set of attributes, SK, of R such that no two tuples in any
valid relational instance, r( R), will have the same value for SK. Therefore,
for any two distinct tuples, t1 and t2 in r( R),
t1[ SK] != t2[SK].
Key of R: A minimal superkey. That is, a superkey, K, of R such that the
removal of ANY attribute from K will result in a set of attributes that are
not a super key.
Example CAR( State, LicensePlateNo, VehicleID, Model, Year, Manufacturer)
K1 = { State, LicensePlateNo}
K2={Vehicle ID}
Both K1 and K2 are superkeys.
K3 = { VehicleID, Manufacturer} is a superkey, but not a key (Why?).
If a relation has more than one keys, we can select any one (arbitrarily) to be the primary key.
Primary Key attributes are underlined in the schema:
The SQL NULL is the term used to represent a missing value. A NULL value in a table is a
value in a field that appears to be blank.
A field with a NULL value is a field with no value. It is very important to understand that a
NULL value is different than a zero value or a field that contains spaces.
Syntax
Here, NOT NULL signifies that column should always accept an explicit value of the given
data type. There are two columns where we did not use NOT NULL, which means these
columns could be NULL.
A field with a NULL value is the one that has been left blank during the record creation.
The NULL value can cause problems when selecting data. However, because when
comparing an unknown value to any other value, the result is always unknown and not
included in the results. You must use the IS NULL or IS NOT NULL operators to check for
a NULL value.
Consider the following CUSTOMERS table having the records as shown below.
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | |
| 7 | Muffy | 24 | Indore | |
+----+----------+-----+-----------+----------+
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
+----+----------+-----+-----------+----------+
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 6 | Komal | 22 | MP | |
| 7 | Muffy | 24 | Indore | |
NULL value means that no entry has been made into the column. It states that the
corresponding value is either unknown or undefined. It is different from zero or "". They
should be avoided to avoid the complexity in select & update queries and also because
columns which have constraints like primary or foreign key constraints cannot contain a
NULL value.
why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.
We should avoid permitting null values because
1.Column with NULL values can't have PRIMARY KEY constraints.
2. Certain calculations can be inaccurate if NULL columns are involved.
Basic SQL:
SQL
What is SQL?
SQL is Structured Query Language, which is a computer language for storing, manipulating
and retrieving data stored in a relational database.
SQL is the standard language for Relational Database System. All the Relational Database
Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix,
Postgres and SQL Server use SQL as their standard database language.
Why SQL?
SQL is widely popular because it offers the following advantages −
Categories in SQL:
Data Definition Language (DDL) - These SQL commands are used for creating,
modifying, and dropping the structure of database objects. The commands are
CREATE, ALTER, DROP, RENAME, and TRUNCATE.
Syntax:
Syntax:
Syntax:
Syntax:
Syntax:
Rename table
Syntax
Syntax:
DROP TABLE <table_name>
Syntax:
Data Manipulation Language (DML) - These SQL commands are used for storing,
retrieving, modifying, and deleting data. These commands are SELECT, INSERT,
UPDATE, and DELETE.
Syntax:
UPDATE:
Syntax:
UPDATE table
SET column1 = expression1,
column2 = expression2,
...
[WHERE conditions];
SQL CONSTRAINTS
Constraints are the rules enforced on the data columns of a table. These are used to limit
the type of data that can go into a table. This ensures the accuracy and reliability of the
data in the database.
Column level : Constraints can be specified at the time of column definition. Column-
level constraints refer to a single column in the table and do not specify a column name
(except check constraints). They refer to the column that they follow.
Syntax: create table table name(col1 datatype constraint constraint name constraint
type,
Table level: Table-level constraints refer to one or more columns in the table. Table-
level constraints specify the names of the columns to which they apply. Table level
constraints are applied to the whole table
Using Alter command: We can use the ALTER TABLE statement to add constraints
even after the table is created.
Syntax:
Alter table table name add constraint constraint name constraint type(column
name);
Following are some of the most commonly used constraints available in SQL.
NOT NULL Constraint − Ensures that a column cannot have a NULL value.
DEFAULT Constraint − Provides a default value for a column when none is specified.
FOREIGN Key − Uniquely identifies a row/record in any of the given database table.
CHECK Constraint − The CHECK constraint ensures that all the values in a column
satisfies certain conditions.
INDEX − Used to create and retrieve data from the database very quickly.
A table can have only one primary key, which may consist of single or multiple fields.
When multiple fields are used as a primary key, they are called a composite key.
If a table has a primary key defined on any field(s), then you cannot have two records
having the same value of that field(s)
This constraint ensures all rows in the table contain a definite value for the column
which is specified as not null. Which means a null value is not allowed
The UNIQUE constraint ensures that all values in a column are different. Both the
UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a
column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE
constraint..We can have many UNIQUE constraints per table, but only one PRIMARY
KEY constraint per table.
A FOREIGN KEY is a field (or collection of fields) in one table that refers to the
PRIMARY KEY in another table.
The table containing the foreign key is called the child table, and the table containing the
candidate key is called the referenced or parent table.
The default value will be added to all new records IF no other value is specified.
Syntax:
Dropping Constraints
Any constraint that you have defined can be dropped using the ALTER TABLE
command with the DROP CONSTRAINT option
The SQL WHERE clause is used to specify a condition while fetching the data from a single
table or by joining with multiple tables. If the given condition is satisfied, then only it returns
a specific value from the table. You should use the WHERE clause to filter the records and
fetching only the necessary records.
The WHERE clause is not only used in the SELECT statement, but it is also used in the
UPDATE, DELETE statement, etc., which we would examine in the subsequent chapters.
Syntax
The basic syntax of the SELECT statement with the WHERE clause is as shown below.
You can specify a condition using the comparison or logical operators like >, <, =, LIKE,
NOT, etc. The following examples would make this concept clear.
Example
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
The following code is an example which would fetch the ID, Name and Salary fields from the
CUSTOMERS table, where the salary is greater than 2000 −
+----+----------+----------+
| ID | NAME | SALARY |
+----+----------+----------+
| 4 | Chaitali | 6500.00 |
| 5 | Hardik | 8500.00 |
| 6 | Komal | 4500.00 |
| 7 | Muffy | 10000.00 |
SQL Operators:
Arithmetic Operators
Operator Meaning
+ (Add) Addition
- (Subtract) Subtraction
* (Multiply) Multiplication
/ (Divide) Division
% (Modulo) Returns the integer
remainder of a division.
For example, 17 % 5 = 2
because the remainder of
17 divided by 5 is 2.
SQL FUNCTIONS:
SQL functions are built into Oracle Database and are available for use in various appropriate SQL
statements.
1) Single Row Functions: Single row or Scalar functions return a value for every row that is
processed in a query.
2) Group or Multiple Functions: These functions group the rows of data based on the values
returned by the query. This is discussed in SQL GROUP Functions. The group functions are used to
calculate aggregate values like total or average, which return just one total or one average value after
processing a group of rows.
1. Numeric Functions or mathematical functions: These are functions that accept numeric
input and return numeric values.
2. Character or Text Functions: These are functions that accept character input and can return
both character and number values.
3. Date Functions: These are functions that take values that are of datatype DATE as input and
return values of datatype DATE, except for the MONTHS_BETWEEN function, which
returns a number.
4. Conversion Functions: These are functions that help us to convert a value in one form to
another form. For Example: a null value into an actual value, or a value from one datatype to
another datatype like NVL, TO_CHAR, TO_NUMBER, TO_DATE etc.
Group functions are built-in SQL functions that operate on groups of rows and return one value for
the entire group. These functions are: COUNT, MAX, MIN, AVG, SUM, DISTINCT, STDDEV
Mathematical Functions
Least Function:
Syntax
Note
If the datatypes of the expressions are different, all expressions will be converted to whatever
datatype expr1 is.
Having a NULL value in one of the expressions will return NULL as the least value.
For Example
least(2, 5, 12, 3) would return 2
Greatest Function
Syntax
expr1, expr2, . expr_n are expressions that are evaluated by the greatest function.
Note
If the datatypes of the expressions are different, all expressions will be converted to whatever
datatype expr1 is.
For Example
greatest(2, 5, 12, 3) would return 12
Ceil function
ceil function returns the smallest integer value that is greater than or equal to a number.
Syntax
ceil( number )
For Example
would return
ceil(32.65)
33
would return
ceil(32)
32
would return
ceil(-32.65)
-32
would return
ceil(-32)
-32
Floor Function
In Oracle/PLSQL, the floor function returns the largest integer value that is
equal to or less than a number.
Syntax
floor( number )
number is the value used to determine the largest integer value that is equal to or
less than a number.
For Example
floor(5.9) would return 5
MOD function:
Syntax
mod( m, n )
m - n * floor(m/n)
Note
The mod function uses the floor function in its formula, whereas the remainder function uses the
round function in its formula.
For Example
would
mod(15, 4)
return 3
would
mod(15, 0) return
15
would
mod(11.6, 2) return
1.6
would
mod(11.6, 2.1) return
1.1
mod(-15, 4) would
return -
3
mod(-15, 0)
Remainder Function
Syntax
remainder( m, n )
The remainder function uses the round function in its formula, whereas the mod
function uses the floor function in its formula.
For Example
remainder(15, 6) would return 3
the round function returns a number rounded to a certain number of decimal places.
Syntax
decimal_places is the number of decimal places rounded to. This value must be an
integer. If this parameter is omitted, the round function will round the number to 0
decimal places.
For Example
would
round(125.315)
return 125
would
round(125.315, 0)
return 125
would
round(125.315, 1) return
125.3
would
round(125.315, 2) return
125.32
would
round(125.315, 3) return
125.315
would
round(-125.315, 2) return -
125.32
Syntax
For Example
trunc(125.815) would return 125
Power Function
Syntax
power( m, n )
m is the base.
n is the exponent.
Note
For Example
power(3, 2) would return 9
Sin Function
Syntax
sin( n )
For Example
would return
sin(3)
0.141120008059867
would return -
sin(5.2)
0.883454655720153
would return
sin(-5.2)
0.883454655720153
Sign Function
Syntax
The syntax for the sign function is:
sign( number )
Note
For Example
would
sign(-23)
return -1
would
sign(-0.001)
return -1
would
sign(0)
return 0
would
sign(0.001)
return 1
would
sign(23)
return 1
would
sign(23.601)
return 1
Log Function
Syntax
log( m, n )
For Example
log(10, 20) would return 1.30102999566398
Exp Function
Syntax
exp( number )
For Example
exp(3) would return 20.0855369231877
Sqrt Function
Syntax
sqrt( n )
n is a positive number.
For Example
sqrt(9) would return 3
Character Functions:
Ascii Function
In Oracle/PLSQL, the ascii function returns the NUMBER code that represents the specified
character.
Syntax
ascii( single_character )
single_character is the specified character to retrieve the NUMBER code for. If more than
one character is entered, the function will return the value for the first character and ignore all
of the characters after the first.
For Example
would return
ascii('t')
116
would return
ascii('T')
84
would also
ascii('T2')
return 84
Chr Function
Syntax
chr( number_code )
For Example
chr(116); would return 't'
Concat Function
Syntax
For Example
concat('Tech on', ' the Net'); would return 'Tech on the Net'
Initcap Function
In Oracle/PLSQL, the initcap function sets the first character in each word to uppercase and
the rest to lowercase.
Syntax
initcap( string1 )
string1 is the string argument whose first character in each word will be converted to
uppercase and all remaining characters converted to lowercase.
For Example
initcap('tech on the net'); would return 'Tech On The Net'
Instr Function
Syntax
start_position is the position in string1 where the search will start. This argument is optional.
If omitted, it defaults to 1. The first position in the string is 1. If the start_position is negative,
the function counts back start_position number of characters from the end of string1 and then
searches towards the beginning of string1.
Note
If string2 is not found in string1, then the instr Oracle function will return 0.
For Example
instr('Tech on the net', 'e') would return 2; the first occurrence of 'e'
instr('Tech on the net', 'e', 1, 1) would return 2; the first occurrence of 'e'
instr('Tech on the net', 'e', 1, 2) would return 11; the second occurrence of 'e'
instr('Tech on the net', 'e', 1, 3) would return 14; the third occurrence of 'e'
Length Function
In Oracle/PLSQL, the length function returns the length of the specified string.
Syntax
length( string1 )
string1 is the string to return the length for. If string1 is NULL, then the function returns
NULL.
For Example
length(NULL) would return NULL
Lower Function
In Oracle/PLSQL, the lower function converts all letters in the specified string to lowercase.
If there are characters in the string that are not letters, they are unaffected by this function.
Syntax
lower( string1 )
For Example
lower('Tech on the Net'); would return 'tech on the net'
lower('GEORGE BURNS 123 '); would return 'george burns 123 '
Upper Function
In Oracle/PLSQL, the upper function converts all letters in the specified string to uppercase.
If there are characters in the string that are not letters, they are unaffected by this function.
Syntax
upper( string1 )
string1 is the string to convert to uppercase.
For Example
upper('Tech on the Net'); would return 'TECH ON THE NET'
upper('george burns 123 '); would return 'GEORGE BURNS 123 '
Lpad Function
In Oracle/PLSQL, the lpad function pads the left-side of a string with a specific set of
characters (when string1 is not null).
Syntax
padded_length is the number of characters to return. If the padded_length is smaller than the
original string, the lpad function will truncate the string to the size of padded_length.
pad_string is optional. This is the string that will be padded to the left-hand side of string1. If
this parameter is omitted, the lpad function will pad spaces to the left-side of string1.
For Example
lpad('tech', 7); would return ' tech'
lpad('tech on the net', 15, 'z'); would return 'tech on the net'
lpad('tech on the net', 16, 'z'); would return 'ztech on the net'
Rpad Function
In Oracle/PLSQL, the rpad function pads the right-side of a string with a specific set of
characters (when string1 is not null).
Syntax
padded_length is the number of characters to return. If the padded_length is smaller than the
original string, the rpad function will truncate the string to the size of padded_length.
pad_string is optional. This is the string that will be padded to the right-hand side of string1.
If this parameter is omitted, the rpad function will pad spaces to the right-side of string1.
For Example
rpad('tech', 7); would return 'tech '
rpad('tech on the net', 15, 'z'); would return 'tech on the net'
rpad('tech on the net', 16, 'z'); would return 'tech on the netz'
Ltrim Function
In Oracle/PLSQL, the ltrim function removes all specified characters from the left-hand side
of a string.
Syntax
string1 is the string to trim the characters from the left-hand side.
trim_string is the string that will be removed from the left-hand side of string1. If this
parameter is omitted, the ltrim function will remove all leading spaces from string1.
For Example
ltrim(' tech'); would return 'tech'
Rtrim Function
rtrim function removes all specified characters from the right-hand side of a string.
Syntax
string1 is the string to trim the characters from the right-hand side.
trim_string is the string that will be removed from the right-hand side of string1. If this
parameter is omitted, the rtrim function will remove all trailing spaces from string1.
For Example
rtrim('tech '); would return 'tech'
Syntax
string1 is the string to replace a sequence of characters with another set of characters.
For Example
replace('123123tech', '123'); would return 'tech'
Substr Function
Syntax
start_position is the position for extraction. The first position in the string is always 1.
If start_position is 0, then substr treats start_position as 1 (ie: the first position in the string).
If start_position is a positive number, then substr starts from the beginning of the string.
If start_position is a negative number, then substr starts from the end of the string and counts
backwards.
For Example
substr('This is a test', 6, 2) would return 'is'
Translate Function
Syntax
string1 is the string to replace a sequence of characters with another set of characters.
For Example
translate('1tech23', '123', '456'); would return '4tech56'
vsize function returns the number of bytes in the internal representation of an expression.
Syntax
vsize( expression )
For Example
vsize('Tech on the net') would return 15
Date Functions
Add_Months Function
Syntax
add_months( date1, n )
date1 is the starting date (before the n months have been added).
For Example
would return '01-Nov-
add_months('01-Aug-03', 3)
03'
would return '01-May-
add_months('01-Aug-03', -3)
03'
Last_Day Function
last_day function returns the last day of the month based on a date
value.
Syntax
last_day( date )
date is the date value to use to calculate the last day of the month.
For Example
last_day(to_date('2003/03/15', 'yyyy/mm/dd')) would return Mar 31, 2003
To_Date Function
Syntax
nls_language is optional. This is the nls language used to convert string1 to a date.
For Example
to_date('2003/07/09', 'yyyy/mm/dd') would return a date value of July 9, 2003
Months_Between Function
months_between function returns the number of months between date1 and date2.
Syntax
date1 and date2 are the dates used to calculate the number of months.
Example #1
months_between (to_date ('2003/01/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd') )
Example #2
months_between (to_date ('2003/07/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd') )
Example #3
months_between (to_date ('2003/07/02', 'yyyy/mm/dd'), to_date ('2003/07/02', 'yyyy/mm/dd') )
would return 0
Example #4
months_between (to_date ('2003/08/02', 'yyyy/mm/dd'), to_date ('2003/06/02', 'yyyy/mm/dd') )
would return 2
Next_Day Function
next_day function returns the first weekday that is greater than a date.
Syntax
For Example
next_day('01-Aug-03', 'TUESDAY') would return '05-Aug-03'
Sysdate function
sysdate function returns the current system date and time on your local database.
Syntax
sysdate
Example #1
select sysdate
from dual;
Syntax
Quarter Q
Week WW
IW IW
W W
Minute MI
For Example
trunc(to_date('22-AUG-03'), 'YEAR') would return '01-JAN-03'
//Term: ROUND
Definition:
In Oracle, ROUND is a built in overloaded function, which is used to round off numeric and
DATE type inputs to a specified precision.
Example Syntax:
ROUND( n, X)
In the syntax example above, "n" can be a numeric or date type input. "X" is the rounding format.
Date type inputs can be rounded by year, month, quarter, week, hour and minute.
Example Usage:
The below set of SQL statements show the use of the ROUND function with both Number and Date
inputs. In the first two examples, note the difference in the results by having positive and negative
precisions. If the precision is positive, it rounds the digits which are placed after the decimal. For
negative precision values, it rounds the digits which are placed before the decimal place.//
ROUND(1.2536,2)
---------------
1.25
ROUND(1234,-2)
--------------
1200
ROUND(TO_
---------
01-JAN-12
ROUND(TO_
---------
01-AUG-11
Round Function (with dates)
Syntax
format is the unit of measure to apply for rounding. If the format parameter is omitted, the
round function will round to the nearest day.
Month MONTH, MON, MM, RM Rounds up on the 16th day of the month
Minute MI
For Example
round(to_date ('22-AUG-03'),'YEAR') would return '01-JAN-04'
To_Char Function
Syntax
format_mask is optional. This is the format that will be used to convert value to a string.
nls_language is optional. This is the nls language used to convert value to a string.
Examples - Numbers
The zeros have been suppressed so that the day component shows as "9" as opposed to "09".
Conversion Functions
Bin_To_Num Function
Syntax
expr1, expr2, ... expr_n must be either 0 or 1 values. They represent bits in a bit vector.
For Example
would
bin_to_num(1)
return 1
would
bin_to_num(1,0)
return 2
would
bin_to_num(1,1)
return 3
would
bin_to_num(1,1,1,0)
return 14
would
bin_to_num(1,1,1,1)
return 15
To_Number Function
Syntax
The syntax for the to_number function is:
format_mask is optional. This is the format that will be used to convert string1 to a
number.
For Example
to_number('1210.73', '9999.99') would return the number 1210.73
Coalesce Function
coalesce function returns the first non-null expression in the list. If all expressions evaluate
to null, then the coalesce function will return null.
Syntax
If the arguments entered are of different datatype then it will throw an error
NVL Function
NVL function lets you substitute a value when a null value is encountered.
Syntax
NVL :-function evaluates whether a column or expression of any datatype is NULL or NOT NULL .
It takes two mandatory parameters. NVL(original,ifnull). Where original refers the term being tested
& ifnull is the result for orignal.
Syntax:- NVL(original,ifnull)
Ex:-
Result returned by this query will be '123' which is ifnull result for original NULL value.
----------------------------------
SELECT NVL ( 125,123 ) FROM DUAL;
Result returned by this query will be '125' which is original NOT NULL value.
----------------------------------
Result returned by this query will be 'value not found' which is ifnull result for original NULL value.
-----------------------------------
Result returned by this query will be 'not null value' which is original NOT NULL value.
-----------------------------------
Result returned by this query will be '01-oct-1988' which is ifnull result for original NULL value.
------------------------------------
Result returned by this query will be '23-mar-1984' which is original NOT NULL value.
Nullif function:
NULLIF Function
NULLIF function compares expr1 and expr2. If expr1 and expr2 are equal, the NULLIF function returns
NULL. Otherwise, it returns expr1.
Syntax
expr1 and expr2 must be either numeric values or values that are of the same datatype.
Note
expr1 can be an expression that evaluates to NULL, but it can not be the literal NULL.
For Example
NULLIF(12, 12) would return NULL
GROUP FUNCTIONS
SQL COUNT (): This function returns the number of rows in the table that satisfies the condition specified in
the WHERE condition. If the WHERE condition is not specified, then the query returns the total number of
rows in the table.
MAX(): This function is used to get the maximum value from a column.
MIN(): This function is used to get the minimum value from a column.
AVG(): This function is used to get the average value of a numeric column.