Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
4-1
Case and Character Manipulation
DPS4L1 3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Purpose
DPS4L1 4
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
DUAL Table
• The DUAL table has one row called "X" and one column called
"DUMMY." DUMMY
X
• The DUAL table is used to create SELECT statements and
execute functions not directly related to a specific database
table.
• Queries using the DUAL table return one row as a result.
DUAL can be useful to do calculations and also to evaluate
expressions that are not derived from a table.
DPS4L1 5
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
DUAL Table
DPS4L1 6
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Single-Row Character Functions
DPS4L1 7
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Single-Row Character Functions
DPS4L1 8
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Case Manipulation Functions
DPS4L1 9
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Case Manipulation Functions
Case-Manipulation Character-Manipulation
Functions Functions
LOWER CONCAT
UPPER SUBSTR
INITCAP LENGTH
INSTR
LPAD | RPAD
TRIM
REPLACE
DPS4L1 10
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Case Manipulation Functions
DPS4L1 11
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Case Manipulation Functions
DPS4L1 12
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 13
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 14
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 15
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 16
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 17
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 18
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 19
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 20
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
DPS4L1 21
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Character Manipulation Functions
Examples: Result
SELECT REPLACE('JACK and JUE','J','BL') BLACK and
FROM DUAL; BLUE
SELECT REPLACE('JACK and JUE','J') ACK and UE
FROM DUAL;
SELECT REPLACE(last_name,'a','*') Abel
FROM employees; D*vies
De H**n
DPS4L1 22
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Using Column Aliases With Functions
DPS4L1 23
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Using Column Aliases With Functions
DPS4L1 24
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Using Column Aliases With Functions
LOWER(LAST_NAME)||LOWER(SUBSTR(FIRST_NAME,1,1))
abele
daviesc
de haanl
DPS4L1 25
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Substitution Variables
• Occasionally you may need to run the same query with many
different values to get different result sets.
• Imagine for instance if you had to write a report of employees
and their departments, but the query must only return data
for one department at a time.
• Without the use of substitution variables, this request would
mean you would have to repeatedly edit the same statement
to change the WHERE-clause.
DPS4L1 26
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Substitution Variables
DPS4L1 27
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Substitution Variables
– Then run it again with different values: 20, 30, 40… etc.
• It could be re-written as:
SELECT first_name, last_name, salary, department_id
FROM employees
WHERE department_id=:enter_dept_id;
DPS4L1 28
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Substitution Variables
DPS4L1 29
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Substitution Variables
DPS4L1 30
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Terminology
DPS4L1 33
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules
Summary
DPS4L1 34
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.
Logical Comparisons and Precedence Rules