0% found this document useful (0 votes)
4 views

Lesson 4 Programming

This document is a lesson on using arithmetic expressions and handling null values in SQL. It includes a pre-test and assessment with true/false statements, technical terms related to SQL functions, and examples of how null values behave in different conditions. Additionally, it provides instructions for generating a report of employee salaries using SQL Developer.

Uploaded by

ALDRIN LLAGAS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lesson 4 Programming

This document is a lesson on using arithmetic expressions and handling null values in SQL. It includes a pre-test and assessment with true/false statements, technical terms related to SQL functions, and examples of how null values behave in different conditions. Additionally, it provides instructions for generating a report of employee salaries using SQL Developer.

Uploaded by

ALDRIN LLAGAS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Using Arithmetic Expressions and

Null Values LESSON 4


Attendance check
CHAPTER
RETRIEVING DATA USING THE 1
SQL SELECT STATEMENT
Lesson 1: Listing Capabilities of SQL SELECT Statements
Lesson 2: Generating Report of Data from the Output of a Basic
Select Statement
Lesson 3: Sorting and Restricting Data
Lesson 4: Using Arithmetic Expressions and NULL Values
Lesson 5: Implementing Column Aliases
Lesson 6: Describing Concatenation Operator, Literal Character
Strings, Alternative Quote Operator, and the Distinct Keyword
Using Arithmetic Expressions and
Null Values LESSON 4
Pre-test

Directions: Write the word


True if the statement is
correct. And Write the word
False if it is incorrect.
__________1. Use two consecutive minus signs (--) in arithmetic
expressions to indicate double negation or the subtraction of a
negative value.
__________2. You should separate consecutive minus signs with a
space or parentheses.
__________3. To check for nulls, use only the comparison conditions
ISNULL and ISNOTNULL.
__________4. Every function always displays a null value except for
the REPLACE, NVL, and CONCAT function.
__________5. If a column in a row has no value, then the column is
said to be null or to contain null.
__________6. If the value of X is 10 and the condition is X IS
NULL, then the result will be a true value.
__________7. If the value of X. is NULL and the condition is
X !=5, then the result will be UNKNOWN.
__________8. If the value of X is null and the condition is X=
15, then the result will be UNKOWN.
__________9. If the value of X is NULL and the condition is
X= NULL, then the result will be a TRUE value.
__________10. If the value of X is NULL and the condition is
X IS NOT NULL, then the result will be a FALSE value.
Using Arithmetic Expressions and
Null Values LESSON 4
1.TRUE 6.FALSE
2.TRUE 7.TRUE
3.TRUE 8.TRUE
4.TRUE 9.FALSE
5.TRUE 10.TRUE
Using Arithmetic Expressions and
Null Values LESSON 4
TECHNICAL TERMS

• CONCAT function - used to concatenate two strings to


form a single string.
• condition - this is an expression of several operators or
expressions that evaluate True or False, or Unknown
• DECODE function – compares expressions to each
search value one by one.
• NVL function – replaces an N/A value or empty string
with a string
TECHNICAL TERMS

• Operators – these are represented by a


single character or reserved words
• REPLACE function – replaces a sequence
of characters in a string with another set
of characters.
• SCALAR function – returns a single value
based on the input value.
Arithmetic Expressions
In SQL expressions, arithmetic
operators are used to add, subtract,
multiply, divide, and negate data
values. In SQL statements, arithmetic
expressions are used to perform a
calculation.
Operator Purpose Example

+~ Unary operator operates SELECT * FROM item WHERE


one on one operand. It y=-1; or SELECT * FROM
denotes a positive or employee WHERE –salary<1;
negative expression.

+~ Binary operator operates on SELECT hire_date FROM


*/ two operands – add or employees WHERE SYSDATE-
subtract and multiply or hire_date>360;
divide. UPDATE employees SET
salary=salary * 2.2;
Using two consecutive minus signs (--) indicates
a double negation or subtraction of a negative
value. In arithmetic expression this may have
different meaning in SQL statements. Two
consecutive minus signs (--) signify the beginning of
the comment WITHIN THE SQL statement. when
using two consecutive minus signs, separate them
by placing a space or parentheses.
NULL VALUES
Some users are often confused with NULL values.
To clarify this misconception, a NULL value does not
pertain to zero value. It is an empty string () value that
represents missing or unknown data, or in applicable
values. It simply indicates that the value unknown. For
instance, if a column in a certain row contains no value,
the column is said to be null, or its value contains a null
value.
NULL VALUES
The null value always appears in all
columns of any data type except for
those columns that have a NOT NULL or
PRIMARY KEY integrity constraint. Use a
null value every time the value is not
recognized or when a value is not
significant anymore
NULL VALUES
When given a NULL value in SQL, almost all of
functions return NULL value except REPLACE, NVL, and
CONCAT. Most aggregate functions ignore the NULL
value.
Whenever a user wants to check for a null value,
he or she should always use the comparison conditions
such as ISNULL and ISNOTNULL. Other conditions will
just display INKNOWN result every time a user wants to
check for a null value.
NULLS IN CONDITIONS
Null value displays different results
based on the conditions set by the
user. The following examples show the
different results displayed every time
a null value is used in a condition.
1. if the condition is X IS NULL and the value of X is 5, then the result in this
example will be a FALSE value because the value of X is 5.
2. if the condition is X IS NOT NULL and the value of X is 5, then the result in this
example will be a TRUE value because the value of X is 5.
3. if the condition is X IS NULL and the value of NULL is 5, then the result in this
example will be a TRUE value because the value of X is a NULL value.
4. if the condition is X IS NOT NULL and the value of X is NULL, then the result in
this example will be a FALSE value because the value of X is NULL but to satisfy
the condition, the value must not be a NULL value.
5. if the condition is X = NULL and the value of X is 5, then the result in this
example will be an UNKNOWN value; that is why there will be no rows to be
returned by that query.
6. if the condition is X != NULL and the value of X is 5 , then the result in this
example will be an UNKOWN value; that is why there will be no rows to be
returned by that query.
7. if the condition is X = NULL and the value of X is NULL, then the result in this
example will be an UNKOWN value; that is why there will be no rows to be
returned by that query.
8. if the condition is X != NULL and the value of X is NULL, then the result in this
example will be an UNKOWN value; that is why there will be no rows to be
returned by that query.
9. if the condition is X = 5 and the value of X is NULL, then the result in this
example will be an UNKOWN value; that is why there will be no rows to be
returned by that query.
10. if the condition is X != 5 and the value of X is NULL, then the result in this
example will be an UNKOWN value; that is why there will be no rows to be
returned by that query.
Skills Needs Improvement Good Excellent
• I Know Arithmetic
Operations and Null
Values.
• I can describe
Arithmetic Operations
and Null Values.
• I can perform
Arithmetic Operations
and Null Values.
Using Arithmetic Expressions and
Null Values LESSON 4
ASSESSMENT

Directions: Write THE WORD


True if the statement is
correct. AND Write THE
WORD False if it is
incorrect.
__________1. Use two consecutive minus signs (--) in arithmetic
expressions to indicate double negation or the subtraction of a
negative value.
__________2. You should separate consecutive minus signs with a
space or parentheses.
__________3. If the value of X is 10 and the condition is X IS NULL,
then the result will be a true value.
__________4. Every function always displays a null value except for
the REPLACE, NVL, and CONCAT function.
__________5. If a column in a row has no value, then the column is
said to be null or to contain null.
__________6. To check for nulls, use only the comparison
conditions ISNULL and ISNOTNULL.
__________7. If the value of X. is NULL and the condition is
X !=5, then the result will be UNKNOWN.
__________8. If the value of X is null and the condition is X=
15, then the result will be UNKOWN.
__________9. If the value of X is NULL and the condition is
X= NULL, then the result will be a TRUE value.
__________10. If the value of X is NULL and the condition is
X IS NOT NULL, then the result will be a FALSE value.
1.TRUE 6.TRUE
2.TRUE 7.TRUE
3.FALSE 8.TRUE
4.TRUE 9.FALSE
5.TRUE 10.TRUE
Using Arithmetic Expressions and
Null Values LESSON 4
Connect to the HR Account to generate a report of employees’ salaries
higher than ten thousand. Do these:
1. Open SQL Developer.
2. Connect to your Oracle database by typing your password.
3. Type the following code:
SELECT MIN_SALARY from JOBS
WHERE MIN_SALARY > 1000
4. Click the Run Statement button or press Ctrl+Enter.
The output should look like this:
RUBRICKS:
Criteria Outstanding Adequate Not Adequate
(6 Pts.) (5 Pts.) (4 Pts.)
Table Creation Created all of the tables defined Created most of the tables Partially created some of the
in project requirements defined in project requirements tables defined in project
Named tables appropriately in Table name was a little unclear in requirements. Table name did not
regard to their data elements regard to its data elements correlate to its data elements

Keys and Entities Correctly choose all primary and Correctly choose most of the Incorrectly choose most of the
foreign keys respecting the primary and foreign keys primary and foreign Keys, and
naming convention respecting the naming convention somehow respected the naming
convention

Implementation Completely populated tables with Populated tables with majority of Populated tables with minimal
correct data elements reflecting data elements outlined in the data elements defined in project
the design design the design

You might also like