8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
1/95
AIRCOM International 1 (95)
ENTERPRISE V6.1OPTIMA Advanced User
PS-TR-PDF-TC-E121-V6.1
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
2/95
OPTIMA Advanced User
2 (95) AIRCOM International
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
3/95
Document Control
AIRCOM International 3 (95)
The information in this document is subject to change without notice and describes only theproduct defined in the introduction of this documentation. This document is intended for theuse of AIRCOM Internationals customers only for the purposes of the agreement under whichthe document is submitted, and no part of it may be reproduced or transmitted in any form ormeans without the prior written permission of AIRCOM International. The document has been
prepared to be used by professional and properly trained personnel, and the customerassumes full responsibility when using it. AIRCOM International welcomes customercomments as part of the process of continuous development and improvement of thedocumentation.
The information or statements given in this document concerning the suitability, capacity, orperformance of the mentioned hardware or software products cannot be considered bindingbut shall be defined in the agreement made between AIRCOM International and the customer.However, AIRCOM International has made all reasonable efforts to ensure that theinstructions contained in the document are adequate and free of material errors andomissions. AIRCOM International will, if necessary, explain issues, which may not be coveredby the document.
AIRCOM Internationals liability for any errors in the document is limited to the documentarycorrection of errors. AIRCOM International WILL NOT BE RESPONSIBLE IN ANY EVENTFOR ERRORS IN THIS DOCUMENT OR FOR ANY DAMAGES, INCIDENTAL OR
CONSEQUENTIAL (INCLUDING MONETARY LOSSES), that might arise from the use of thisdocument or the information in it.
This document and the product it describes are considered protected by copyright accordingto the applicable laws.
OPTIMA is a registered trademark of AIRCOM International.
Other product names mentioned in this document may be trademarks of their respectivecompanies, and they are mentioned for identification purposes only.
Copyright AIRCOM International 2007. All rights reserved.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
4/95
OPTIMA Advanced User
4 (95) AIRCOM International
Document Control
Change History
Version Date Author Description
1 14/10/2005 D. Ramirez Creation of document
1 14/10/2005 F. Martinez Review and approve
2 07/11/2005 D. Ramirez CASE expression added
2 08/11/2005 F. Martinez Review and approve
3 08/10/2007 JL. Martinez Update version 5.2
Reviewers
Name Description
F. Martinez Director of Technology Solutions
Related DocumentsReference Document Number Title
1PS-TR-PDF-TC-E105-V5.0.1-1
OPTIMA Tool User V5.0.1
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
5/95
Contents
AIRCOM International 5 (95)
Contents
Document Control................................................................................................ 4Change History ................................................................................................... 4Reviewers ................................................................................................... 4Related Documents ............................................................................................... 4
Contents ................................................................................................... 5
Scope and Course Objectives............................................................................. 9Course Objectives.................................................................................................. 9Sessions ................................................................................................. 10Course Timetable................................................................................................. 11
1 OPTIMA Modules Overview ................................................... 121.1 Objectives of this session ......................................................... 121.2 Introduction to OPTIMA Modules.............................................. 121.3 Module Explorer ....................................................................... 131.4 Viewing Modules ...................................................................... 141.5 Importing / Exporting Modules .................................................. 141.6 Session Summary Checklist .............................................. 15
2 Introduction to Databases and SQL...................................... 162.1 Objectives of this session ......................................................... 162.2 Relational Databases................................................................ 162.2.1 Database Objects ..................................................................... 162.2.2 Schemas .................................................................................. 162.2.3 Tables....................................................................................... 172.3 Introduction to SQL................................................................... 182.3.1 Data Query Language .............................................................. 182.4 Basic SQL statements and concepts ........................................ 192.4.1 The SELECT statement............................................................ 192.4.2 The FROM clause .................................................................... 202.4.3 Conditions and the WHERE clause .......................................... 202.4.4 Sorting data and the ORDER BY clause................................... 212.4.5 Column Aliases......................................................................... 22
2.5 SQL Operators ......................................................................... 222.5.1 Comparison Operators ............................................................. 222.5.2 Logical Operators ..................................................................... 242.5.3 Conjunctive Operators.............................................................. 262.5.4 Arithmetic Operators................................................................. 262.6 Session Summary Checklist .............................................. 28
3 Summarising and Grouping Data.......................................... 293.1 Objectives of this session ......................................................... 293.2 Aggregate Functions................................................................. 29
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
6/95
OPTIMA Advanced User
6 (95) AIRCOM International
3.2.1 The COUNT function ................................................................ 293.2.2 The SUM function..................................................................... 303.2.3 The MIN and MAX functions ..................................................... 303.2.4 The AVG function ..................................................................... 30
3.3 Grouping and Sorting Data ....................................................... 313.3.1 The GROUP BY clause ............................................................ 313.3.2 Creating groups and using aggregate functions........................ 313.3.3 GROUP BY vs. ORDER BY...................................................... 313.3.4 The HAVING clause .................................................................323.4 Session Summary Checklist .............................................. 33
4 Working with Dates and Times.............................................. 344.1 Objectives of this session ......................................................... 344.2 DATE and TIMESTAMP data types .......................................... 344.3 Getting the current Date: SYSDATE ......................................... 34
4.4 Adding Time to Dates: INTERVAL............................................ 354.5 Adding Time to Dates without INTERVAL.................................354.6 Truncating dates: TRUNC......................................................... 354.7 Converting Dates to Character strings ...................................... 364.8 Session Summary Checklist .............................................. 37
5 Joining Tables and Sub-Queries ........................................... 385.1 Objectives of this session ......................................................... 385.2 Selecting data from multiple tables (Joins)................................ 385.3 Types of Joins .......................................................................... 385.3.1 EQUIJOINS .............................................................................. 395.3.2 OUTER JOINS.......................................................................... 39
5.3.3 SELF JOINS............................................................................. 405.3.4 Using a BASE Table to JOIN .................................................... 405.4 Subqueries ............................................................................... 405.5 Session Summary Checklist .............................................. 42
6 Other SQL statements and Performance Issues .................. 436.1 Objectives of this session ......................................................... 436.2 Miscellaneous Character Functions.......................................... 436.2.1 DECODE .................................................................................. 436.2.2 CASE........................................................................................ 446.2.3 ROUND ....................................................................................456.2.4 NVL .......................................................................................... 45
6.3 Performance Issues.................................................................. 466.3.1 Formatting SQL statements for readability ................................ 466.3.2 Ordering tables in the FROM clause......................................... 466.3.3 Order of the most restrictive conditions..................................... 466.3.4 Using the LIKE operator and Wildcards .................................... 476.3.5 Avoiding the OR operator ......................................................... 476.3.6 Avoiding the HAVING clause .................................................... 476.3.7 Avoiding large sort operations................................................... 476.4 Session Summary Checklist .............................................. 48
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
7/95
Contents
AIRCOM International 7 (95)
7 SQL Exercises ........................................................................ 497.1 Objectives of this session ......................................................... 497.2 Simple Queries......................................................................... 497.2.1 SELECT FROM........................................................................ 49
7.2.2 SELECT DISTINCT.................................................................. 497.2.3 WHERE.................................................................................... 507.2.4 ORDER BY............................................................................... 507.2.5 ORDER BY, with integers as identifiers .................................... 507.2.6 Column Aliases......................................................................... 507.3 Queries using operators ........................................................... 507.3.1 Comparison Operators ............................................................. 507.3.2 Logical Operators: IS NULL...................................................... 507.3.3 Logical Operators: BETWEEN.................................................. 517.3.4 Logical Operators: IN................................................................ 517.3.5 Logical Operators: LIKE............................................................ 517.3.6 Conjunctive Operators: AND..................................................... 517.3.7 Conjunctive Operators: OR....................................................... 517.3.8 Arithmetic Operators................................................................. 517.4 Queries using Summaries and Grouping.................................. 517.4.1 Aggregate Functions: COUNT.................................................. 517.4.2 Aggregate Functions: SUM....................................................... 527.4.3 Aggregate Functions: MIN, MAX and AVERAGE...................... 527.4.4 GROUP BY with Aggregate functions....................................... 527.4.5 HAVING.................................................................................... 527.5 Queries using Dates and Time ................................................. 527.5.1 SYSDATE................................................................................. 527.5.2 INTERVAL................................................................................ 52
7.5.3 Adding dates without using INTERVAL..................................... 537.5.4 Using the TRUNC ( ) function ................................................... 537.5.5 Selecting data using BETWEEN and SYSDATE....................... 537.6 Joins and Subqueries ............................................................... 537.6.1 EQUIJOINS.............................................................................. 537.6.2 Sub Queries ............................................................................. 537.7 ROUND, DECODE and NVL .................................................... 537.7.1 ROUND .................................................................................... 547.7.2 DECODE.................................................................................. 547.7.3 CASE ....................................................................................... 547.7.4 NVL .......................................................................................... 547.8 Session Summary Checklist .............................................. 55
8 Creating OPTIMA Modules..................................................... 568.1 Objectives of this session ......................................................... 568.2 Creating Modules ..................................................................... 568.2.1 Data Explorer Window.............................................................. 578.2.2 Query Builder............................................................................ 598.3 Defining a query using the Builder Tab ..................................... 598.4 Defining a query using the SQL Tab......................................... 638.5 Using SQL................................................................................ 64
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
8/95
OPTIMA Advanced User
8 (95) AIRCOM International
8.5.1 SQL SELECT and FROM Commands................................... 648.5.2 SQL DISTINCT Command...................................................... 658.5.3 SQL WHERE Command ......................................................... 658.5.4 SQL GROUP BY Command.................................................... 67
8.5.5 SQL HAVING Command......................................................... 678.5.6 SQL ORDER BY Command.................................................... 678.5.7 Filters Tab................................................................................. 688.5.8 Preview Tab..............................................................................698.6 Editing Modules........................................................................ 718.7 Deleting Modules...................................................................... 718.8 Session Summary Checklist ............................................. 72
9 Creating OPTIMA Reports...................................................... 739.1 Objectives of this session ......................................................... 739.2 Introduction............................................................................... 73
9.3 The Report Explorer .................................................................749.4 Creating Reports in Optima....................................................... 769.5 Report Designer........................................................................ 769.5.1 Data tab.................................................................................... 779.5.2 Design tab ................................................................................ 859.5.3 Preview tab............................................................................... 939.5.4 Save a Report........................................................................... 949.6 Session Summary Checklist ............................................. 95
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
9/95
Scope and Course Objectives
AIRCOM International 9 (95)
Scope and Course Objectives
This document provides notes and supporting material for the OPTIMA Advanced User TrainingCourse. It is assumed that the software tool has been installed and the system administrator has
configured a suitable Oracle database.
Details of how to install the software tool and how to setup a new database source are covered by the
ENTERPRISE Administration Course and the OPTIMA Administrator Course, and not by the
OPTIMA Advanced User Training Course.
Course Objectives
The OPTIMA Advanced User Course is designed for Network Optimisation Engineers who will be
using OPTIMA a performance monitoring facility that monitors and identifies problems in the
network.
It is advisable that course delegates have a very good knowledge of various BSS parameters utilised
for monitoring and optimising Mobile networks.
At the end of the course, delegates should gain knowledge to enable them to have a solid grasp of the
OPTIMA Tool. Delegates will also be able to complete the following objectives:
Understand the concept of Optima Modules
Understand the basics of SQL
Create Moderate to Advanced Optima Modules
Understand how to use Report Builder within Optima
Create Optima Reports
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
10/95
OPTIMA Advanced User
10 (95) AIRCOM International
Sessions
This course is divided into the following sessions:
1. OPTIMA Modules Overview
2. Introduction to Databases and SQL
3. Summarising and Grouping Data
4. Working with Dates & Times
5. Joining Tables and Sub Queries
6. Other SQL commands and Performance Issues
7. SQL Exercises
8. Creating Optima Modules
9. Creating Optima Reports
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
11/95
Scope and Course Objectives
AIRCOM International 11 (95)
Course Timetable
Day 1 Day 2
Period Plan Period Plan
0930-1000 Session 1 : OPTIMA Modules
Overview
0915-1000 Session 8 : Creating Simple
Modules
1000-1045 Session 2 : Introduction toDatabases and SQL
1000-1045 Session 9 : Creating ModerateModules
1045-1100 Break 1045-1100 Break
1100-1145 Session 3 : Summarising and
Grouping Data
1100-1145 Session 10 : Creating Advanced
Modules
1145-1230 Session 4 : Working with Dates
& Times
1145-1230 Session 11 : Advice for creating
efficient Modules
1230-1330 Lunch 1230-1330 Lunch
1330-1415 Session 5 : Joining Tables & Sub
Queries
1330-1415 Session 12 : The Optima Report
Builder
1415-1500 Session 6: Other SQL commands
and Performance Issues
1415-1500 Session 13 : Creating Optima
Reports
1500-1515 Break 1500-1515 Break
1515-1600 Session 7 : SQL Exercises 1515-1600 Session 13 : Creating Optima
Reports
1600-1630 Session 7 : SQL Exercises 1600-1630 Course Evaluation & Feedback
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
12/95
OPTIMA Advanced User
12 (95) AIRCOM International
1 OPTIMA Modules Overview
1.1 Objectives of this session
During this session you will learn about:
OPTIMA Modules
The Module Explorer
Importing/Exporting Modules
1.2 Introduction to OPTIMA Modules
An OPTIMA Module consists of: -
Numerous details, which includes; Module name, Module description, creators name, creation
date, name of last person to edit the module and the date last edited.
A database query, written in Standard Query Language (SQL), that enables the creation of anetwork element selection tree, together with the type of data you wish to be displayed.
Database queries return data when nodes are selected from the tree-view. A separate query can be
defined for each tree level. For example, you may have BSCs on one level and cells on the next level.
Therefore you could have a query for each of these.
If you are logged into OPTIMA Lite with OPTIMA User permissions, you will only have read-only
access to modules. However, when logged into OPTIMA Lite with OPTIMA_Advanced_User or
OPTIMA_Administrator permissions you will be able to create, edit, delete, import and export
modules.
The creation of modules is carried out within the Module Explorer window and can only be carried out
with those who have sufficient user privileges; these being Advanced_users and Administrators.
In creating a module you are creating an SQL query which will run against the OPTIMA database, so
it is advisable that you have some experience with Oracle and SQL.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
13/95
OPTIMA Modules Overview
AIRCOM International 13 (95)
1.3 Module Explorer
As its name suggests the Module Explorer provides a user interface in which to create, edit, delete,
import or export modules (depending on your assigned privileges). Once opened, either from the
Inspector menu, or by clicking on the Module Explorer button , the user will be presented with a
window containing two distinct areas:
1. All Folders Area
2. Contents of Folders Area
The left side of the Module Explorer window (All Folders area) contains a directory structure of
folders in which to save completed modules.
Upon selecting a folder containing modules of interest, a list of the folders contents (i.e. modules)
appears in the right side (Contents of Folders area) of the window. A choice to view the modules as a
list or with their details exists within a sub-menu that can be accessed by right clicking in the right
pane of the window. From the sub-menu that appears, point to View and select either List or Details.
If the Details option is chosen each module name is displayed along with its description, current state
(enabled/not enabled), date and person who last modified it.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
14/95
OPTIMA Advanced User
14 (95) AIRCOM International
1.4 Viewing Modules
A standard OPTIMA installation would normally include a number of preconfigured modules, which
have been included upon request from the customer or included for training purposes. These pre-
configured Modules can also be imported from a standard ENTERPRISE installation disk. Any
OPTIMA user can view modules, which is done by double-clicking on the module of interest.
1.5 Importing / Exporting Modules
As previously mentioned, individual modules can be imported or exported from OPTIMA Inspector.
Having highlighted the Folder you wish to import the module to, from the File menu select Import.
Alternatively you can select the Import Module from file button located within the Module
Explorer toolbar.
To export a module, select the module for export and click on the Export Module from file
button .
Alternatively, from the File menu you can select the Export option.
Whether you are importing or exporting modules, message boxes will appear prompting you to
confirm your actions.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
15/95
OPTIMA Modules Overview
AIRCOM International 15 (95)
1.6 Session Summary Checklist
This checklist has been provided as a self-assessment of the objectives stated at the beginning of the
session.
Please tick all objectives covered in this Session:
Optima Modules
The Module Explorer
Importing/Exporting Modules
Additional Notes:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
16/95
OPTIMA Advanced User
16 (95) AIRCOM International
2 Introduction to Databases and SQL
2.1 Objectives of this session
During this session you will learn about:
Relational Databases
Introduction to SQL
Basic SQL statements and concepts
SQL Operators
2.2 Relational Databases
The Optima System utilises an Oracle Database for storage and data management purposes. An Oracle
database, along with its related software, is a Relational Database Management System (RDBMS).
A Database is a collection of data. A Relational Database is one that is divided into logical units called
tables, with these tables related to one another inside the database. Having data neatly organised into
related tables allows for easy data retrieval using a single query. Also, by having common keys or
fields on these tables, data from multiple tables can be joined to form one larger data set. This largely
avoids data redundancy, which economises space and speeds up searches.
Relational Databases are highly structured and organised. Because of this, there are a variety of
concepts that need to be introduced.
2.2.1 Database Objects
A Database object is any defined object in a database that is used to store or reference data. Examplesof Database objects include Tables, Views, Indexes, Synonyms and others.
2.2.2 Schemas
A Schema is a collection of database objects associated with one particular database username.
Basically, any user who creates an object has its own schema. Tables can be called the same as long as
they belong to different schemas. An example of this is:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
17/95
Introduction to Databases and SQL
AIRCOM International 17 (95)
ERICSSON3G.TRAFFIC and NOKIA3G.TRAFFIC
If you dont specify a schema with the table name, when running a query, the database will look for
that table in the schema that you own according to your username.
In the Optima database, there are Schemas for each vendor in the network, such as the Ericsson
schema, the Nokia schema, etc. There is also an AIRCOM schema, which includes all the tables
related to the operation of Optima and a Global schema, to store Views and other objects that relate to
multiple vendors.
2.2.3 Tables
The table is the primary storage object for data in relational database. A table consists of Records(rows) and Fields (columns). A table takes up physical space in a database and can be permanent or
temporary.
A Fieldis a column in a table that is designed to maintain specific information about every record in
the table. In Optima, field names reflect the Performance Counters names as provided by the vendors.
Some examples could be: UTRANCELL, DATETIME, RRC_ESTAB_FR, RRC_ATT, RRC_SUCC.
ARecordis a horizontal entity in a table, in other words, a row of data. In Optima, Records refer to a
particular instant in time, typically 1 hour, in which data was recorded into a number of different
Fields.
2.2.3.1 Primary Key Constraints
Primary key is the term used to identify one or more columns in a table that make a row of data
unique. More than one column can comprise the primary key. The primary key is a column that is
normally referenced in queries, particularly to join tables.
2.2.3.2 Foreign Key Constraints
A Foreign key is a column in a child table that references a primary key in the parent table. A Foreign
key constraint is the main mechanism used to enforce referential integrity between tables in relational
database. A column defined as a foreign key is used to reference a column defined as a primary key in
another table.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
18/95
OPTIMA Advanced User
18 (95) AIRCOM International
2.2.3.3 NULL Values
NULL is the term used to represent a missing value. A field with a NULL value is a field with no
value. A NULL value is different from zero or a field that contains spaces. A field with a NULL value
is one that has been left blank during record creation.
2.3 Introduction to SQL
SQL is the set of commands used to communicate with a Relational Database, such as the Optima DB.
SQL was developed by IBM based on Dr. E.F. Codds paper A relational model of Data for Large
Shared Data Banks. The ANSI SQL is a standardised version of SQL, which has been adopted also
by the ISO, making it the most widely accepted version of SQL. The Oracle implementation of SQL
conforms largely with the ANSI SQL, so it represents no problem when working with other
RDBMSs.
SQL can be used for many database tasks, such as building database objects, populating database
tables, deleting data as well as running simple queries.
SQL commands can be divided into the following categories:
DDL (Data Definition Language): Used to create and restructure database objects. Someexamples of commands of this type include CREATE TABLE, DROP TABLE and others.
DML (Data Manipulation Language): Used to manipulate data within objects of a relationaldatabase. The three basic DML commands are INSERT, UPDATE, DELETE.
DCL (Data Control Language): DCL deals with the controlled access to data. Some examplesof these commands include GRANT, REVOKE and ALTER PASSWORD.
Data administration commands: these commands allow administrators to audit and analyseoperations in the database. Examples are START AUDIT and STOP AUDIT.
Transactional control commands: such as COMMIT, ROLLBACK and others
DQL (Data Query Language): there is only one command in this category, which is theSELECT command.
2.3.1 Data Query Language
As mentioned before, DQL is only made of a single command. But the SELECT command, along with
many options and clauses, is sufficient to allow users to run the most complex database queries.
A database query is an inquiry to the database for some of its data. To make this query, an application
interface is commonly used. The Oracle software is this application interface. The Optima front end
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
19/95
Introduction to Databases and SQL
AIRCOM International 19 (95)
acts as a further interface between the end user and the Oracle system. The Optima Modules are used
to store such queries for further use, as explained on the previous section.
It is also possible to run database queries from other applications, such as SQL plus or TOAD, but
they require a thorough knowledge of SQL and Oracle databases, whereas Optima has been made withthe everyday user in mind.
2.4 Basic SQL statements and concepts
The SELECT statement, the command that represents Data Query Language (DQL) in SQL, is the
statement used to construct database queries. The SELECT statement is not a standalone statement,
that is, one or more additional clauses are required for a proper query. In addition to the requiredclauses, there are optional clauses that increase the overall functionality of the SELECT statement.
The FROM clause is the mandatory clause and must always be used in conjunction with the SELECT
statement.
There are four keywords, or clauses, that are valuable parts of a SELECT statement. These keywords
are as follows:
SELECT
FROM
WHERE
ORDER BY
Each of these keywords is covered in detail next
2.4.1 The SELECT statement
The SELECT statement is used in conjunction with the FROM clause to extract data from the database
in an organized, readable format. The SELECT part of the query is for selecting the data you want to
see according to the columns in which they are stored in a table.
The syntax for a simple SELECT statement is as follows:
SELECT [ * | ALL | DISTINCT COLUMN 1, COLUMN 2 ]
FROM TABLE 1 [ , TABLE 2 ] ;
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
20/95
OPTIMA Advanced User
20 (95) AIRCOM International
The SELECT keyword in a query is followed by a list of columns that you want displayed as part of
the query output. The FROM keyword is followed by a list of one or more tables from which you want
to select data. The asterisk (*) is used to denote that all columns in a table should be displayed as part
of the output. The ALL option is used to display all values for a column, including duplicates. The
DISTINCT option is used to suppress duplicate rows from being displayed in the output. The defaultselection is ALL, but it does not need to be specified. All the columns following the SELECT are
separated by commas, as are the tables in the FROM clause.
2.4.2 The FROM clause
The FROM clauses purpose is to tell the database what table(s) to access to retrieve the desired data
for the query. The FROM clause may contain one or more tables. The FROM clause must always list
at least one table.
The syntax for the FROM clause is as follows:
FROM TABLE [, TABLE 2 ]
2.4.3 Conditions and the WHERE clause
A condition is part of a query that is used to display selective information as specified by the query.
The WHERE clause is used to place conditions on a query by eliminating rows that would normally
be returned by a query without conditions.
There can be more than one condition in the WHERE clause. If there is more than one condition, they
are connected by the AND and OR operators. There are several conditional operators than can be
used to specify conditions in a query. An operatoris a character or keyword in SQL that is used to
combine elements in a SQL statement. Alphanumeric data types need to be specified with single
quotation marks ( )
The syntax for the WHERE clause is as follows:
SELECT [ ALL | * | DISTINCT COLUMN 1 , COLUMN 2 ]
FROM TABLE 1 [ , TABLE 2 ]
WHERE [ CONDITION 1 | EXPRESSION 1]
[AND CONDITION 2 | EXPRESSION 2]
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
21/95
Introduction to Databases and SQL
AIRCOM International 21 (95)
2.4.4 Sorting data and the ORDER BY clause
Data can be sorted by using the ORDER BY clause. The ORDER BY clause arrange the results of aquery in a format that you specify. The default ordering of the ORDER BY clause is ascending, which
would display 1-9 and A-Z. A descending orderwould be displayed as Z-A or 9-1.
SQL sort are ASCll, character-based sorts. The numeric value 0-9 would be sorted as character values,
and sorted before the characters A-Z. because numeric values are treated like characters during a sort,
the following list of numeric values would be sorted in the following order: 1, 12, 2, 255, 3.
The syntax for the ORDER BY is as follows:
SELECT [ ALL ] * | DISTINCT COLUMN 1 , COLUMN2 ]
FROM TABLE 1 [ , TABLE2 ]
WHERE [ CONDITION1 | EXPRESSION1]
[ AND CONDITION 2 | EXPRESSION 2]
ORDER BY COLUMN1 | INTEGER [ ASC | DESC ]
Note the use of the ASC option. ASC can be specified after any column in the ORDER BY clause.
You can order by multiple columns in a query, using either the column name itself or the associated
number of the column in the SELECT.
ORDER BY 1, 2, 3
Columns in an ORDER BY clause are not required to appear in the same order as the associated
columns following the SELECT, as shown by following example:
ORDER BY 1, 3, 2
Data in SQL is case-sensitive, so, it is advisable to store all data exclusively in upper case to provide
data consistency.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
22/95
OPTIMA Advanced User
22 (95) AIRCOM International
2.4.5 Column Aliases
Column Aliases are used to rename a tables columns for the purpose of a particular query. The syntaxof Aliases is as follows:
SELECT COLUMN_NAME ALIAS_NAME
FROM TABLE_NAME;
Column aliases can be used to customise names for column headers, and can also be used to reference
a column with a shorter name in some SQL implementations. Aliases cannot be used in the WHERE
clause.
When a column is renamed in a SELECT statement, the name is not a permanent change. The changeis only for that particular SELECT statement.
2.5 SQL Operators
An operator is a reserved word or a character used primarily in an SQL statements WHERE clause to
perform operations such as comparisons or arithmetic calculations. Operators are used to specify
condition in a SQL statement and to serve as conjunctions for multiple conditions in a statement.
2.5.1 Comparison Operators
Comparison Operators are used to test single value in a SQL statement. The comparison operators
discussed consist of =, < >, < , and >.
These operators are used to test for:
Equality
Non-equality Less-than values
Grater-than values
Examples and the meanings of comparison operators are shown next.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
23/95
Introduction to Databases and SQL
AIRCOM International 23 (95)
2.5.1.1 Equality
The equal operator compares single values to one another in an SQL statement. When testing for
equality, the compared values must match exactly or no data is returned.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE CELL= CELL_A
2.5.1.2 Non-Equality
The non-equal operator, < >, returns a TRUE value if the condition finds a non-equality between the
compared values.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE CELL CELL_A
2.5.1.3 Less-than, Greater-than
These symbols, < or >, can be used alone or in combination with each other or other operators.
Example:
SELECT *FROM ERICSSON3G.CELLSTATS
WHERE TRAFFIC > 10
These operators are not inclusive, so, you may need to combine them with the equal operator if you
want the declared value to be included in the results, as shown next:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE TRAFFIC >= 10
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
24/95
OPTIMA Advanced User
24 (95) AIRCOM International
2.5.2 Logical Operators
Logical Operators use SQL keywords, instead of symbols, to make comparisons. Some of the most
used SQL logical operators are:
IS NULL
BETWEEN
IN
LIKE
2.5.2.1 The IS NULL operator
The IS NULL operator is used to compare a value with the NULL value. This operator can be used tosearch for records that are missing values on any particular fields.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE CELL IS NULL
This is not the same as writing this:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE CELL= NULL
2.5.2.2 The BETWEEN operator
The BETWEEN operator is used to search for values that are between a set of minimum and
maximum values. These min and max values are included on the conditional set.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE TRAFFIC BETWEEN 10 AND 15
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
25/95
Introduction to Databases and SQL
AIRCOM International 25 (95)
2.5.2.3 The IN operator
The IN operator is used to compare a value to a list of specified literal values. The compared value
must match at least one of the values on the list.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE TRAFFIC IN (10, 15, 20)
The IN operator can achieve the same results as the OR Conjunctive operator presented next, and
could be faster.
2.5.2.4 The LIKE operator
The LIKE operator is used to compare a value to similar values using wildcard operators. There are
two wildcards used with the LIKE operator:
The percent sign (%)
The underscore (_)
The percent sign represents zero, one or multiple characters. The underscore represents a single
number or character. The symbols are used in combinations.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATSWHERE CELL LIKE GU1%
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
26/95
OPTIMA Advanced User
26 (95) AIRCOM International
2.5.3 Conjunctive Operators
Conjunctive Operators are used to combine several conditions. The conjunctive operators are:
AND
OR
2.5.3.1 The AND operator
The AND operator allows the existence of multiple conditions in a WHERE statement. For an action
to be taken by the SQL statement all conditions separated by the AND operator must be TRUE.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE CELL= GU1001 AND DATETIME= 04/10/2005 17:00:00
2.5.3.2 The OR operator
The OR operator is used to combine multiple conditions in a WHERE statement. For an action to be
taken by the SQL statement at least one of the conditions separated by the OR operator must be
TRUE.
Example:
SELECT *
FROM ERICSSON3G.CELLSTATS
WHERE CELL= GU1001 OR CELL=GU1002
2.5.4 Arithmetic Operators
Arithmetic Operators are used to perform mathematical functions in SQL. There are four operators formathematical functions:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
27/95
Introduction to Databases and SQL
AIRCOM International 27 (95)
In SQL, arithmetic operators follow the rules of precedence, where multiplication or division
operations are performed first, and then additions and subtractions. However, you can use parentheses
to control the order of these operations, as illustrated next:
1 + 1 * 5 = 6(1+1) * 5 = 10
10 4 / 2 + 1 = 9
(10 4) / (2 + 1) = 2
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
28/95
OPTIMA Advanced User
28 (95) AIRCOM International
2.6 Session Summary Checklist
This checklist has been provided as a self-assessment of the objectives stated at the beginning of the
session.
Please tick all objectives covered in this Session:
Relational Databases
Introduction to SQL
Basic SQL statements and concepts
SQL operators
Additional Notes:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
29/95
Summarising and Grouping Data
AIRCOM International 29 (95)
3 Summarising and Grouping Data
3.1 Objectives of this session
During this session you will learn about:
Aggregate Functions
Grouping Functions
Sorting Functions
3.2 Aggregate Functions
A function is a command always used in conjunction with a column name or expression. There are
several types of functions in SQL. An Aggregate function is used to provide summarisation
information for an SQL statement, such as count, totals and averages.
The aggregate functions are:
COUNT
SUM
MAX
MIN
AVG
3.2.1 The COUNT function
The COUNT function is used to count rows or values of a column that do not contain a NULL value.When used with a query, the COUNT function returns a numeric value. When the COUNT function is
used with the DISTINCT command, only the distinct rows are counted. COUNT * counts all the rows
of a table including duplicates, whether a NULL value is contained in a column or not.
The syntax for the COUNT function is as follows:
COUNT [ (*) (DISTINCT ALL ) ] (COLUMN NAME )
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
30/95
OPTIMA Advanced User
30 (95) AIRCOM International
3.2.2 The SUM function
The SUM function is used to return a total on the values of a column for a group of rows. The SUM
function can also be used in conjunction with DISTINCT. When this is done, only the distinct rowsare totalled, which may not be useful. The value of an argument must be numeric to use the SUM
function.
The syntax for the SUM function is as follows:
SUM ( [ DISTINCT ] (COLUMN NAME )
3.2.3 The MIN and MAX functions
The MIN and MAX functions are used to return the minimum and maximum values, respectively, for
a column in a group of rows. NULL values are ignored when using these functions. Even though the
DISTINCT command can be used, it is useless.
The syntax for the MIN/MAX functions is as follows:
MIN ( [ DISTINCT ] (COLUMN NAME )
MAX ( [ DISTINCT ] (COLUMN NAME )
3.2.4 The AVG function
The AVG function is used to return the average for a group of rows. The AVG function can also be
used in conjunction with DISTINCT. When this is done, only the distinct rows are averaged. The
value of an argument must be numeric to use the AVG function.
The syntax for the AVG function is as follows:
AVG ( [ DISTINCT ] (COLUMN NAME )
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
31/95
Summarising and Grouping Data
AIRCOM International 31 (95)
3.3 Grouping and Sorting Data
Grouping data is the process of combining the columns with duplicate values in a logical order.Grouping data is accomplished through the use of the GROUP BY clause of a SELECT statement.
3.3.1 The GROUP BY clause
The GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER
BY clause. The syntax of the GROUP BY clause, and its position in a query, is as follows:
SELECT COLUMN1, COLUMN2
FROM TABLE1, TABLE2
WHERE CONDITIONSGROUP BY COLUMN1, COLUMN2
ORDER BY COLUMN1, COLUMN2
If a column is not found on the SELECT statement it cannot be used in the GROUP BY clause. If the
column name has been qualified, the qualified name must go into the GROUP BY clause.
3.3.2 Creating groups and using aggregate functions
There are conditions that the SELECT clause has that must be met when using GROUP BY.Specifically, whatever columns are selected must appear in the GROUP BY clause, except for any
aggregate values.
The columns in the GROUP BY clause do not necessarily have to be in the same order as they appear
in the SELECT clause.
3.3.3 GROUP BY vs. ORDER BY
The GROUP BY clause and the ORDER BY clause work in the same way as far as sorting data. The
ORDER BY clause is specifically used to sort data from a query; the GROUP BY clause also sortsdata from a query to properly group the data. Therefore, the GROUP BY clause can be used to sort
data as the ORDER BY clause.
However, there are some differences and disadvantages in using GROUP BY to sort data:
All non-aggregate columns selected must be listed in the GROUP BY clause.
Integers cannot be used in the GROUP BY clause to represent columns after the SELECTstatement, like they can in the ORDER BY clause
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
32/95
OPTIMA Advanced User
32 (95) AIRCOM International
The GROUP BY clause is not necessary generally unless using aggregate functions
The GROUP BY clause is designed to group identical data, whereas the ORDER BY isdesigned merely to put data in a specific order.
Finally, both clauses can be used in the same SELECT statement, but most follow a specific order in
which the GROUP BY clause is always placed before the ORDER BY clause.
3.3.4 The HAVING clause
The HAVING clause, when used in conjunction with the GROUP BY in a select statement, tells the
GROUP BY which groups to include in the output. HAVING is to GROUP BY as WHERE is to
SELECT. In other words, the WHERE cause places conditions on the selected columns, whereas the
HAVING clause places conditions on groups created by the GROUP BY clause.
The HAVING clause must follow the GROUP BY clause in a query and must also precedes the
ORDER BY clause, if used.
The syntax of the HAVING clause, and its position in a query, is as follows:
SELECT COLUMN1, COLUMN2
FROM TABLE1, TABLE2
WHERE CONDITIONS
GROUP BY COLUMN1, COLUMN2
HAVING CONDITIONS
ORDER BY COLUMN1, COLUMN2
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
33/95
Summarising and Grouping Data
AIRCOM International 33 (95)
3.4 Session Summary Checklist
This checklist has been provided as a self-assessment of the objectives stated at the beginning of the
session.
Please tick all objectives covered in this Session:
Aggregate Functions
Grouping Functions
Sorting Functions
Additional Notes:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
34/95
OPTIMA Advanced User
34 (95) AIRCOM International
4 Working with Dates and Times
4.1 Objectives of this session
During this session you will learn about:
DATE and TIMESTAMP data types
Getting the current date: SYSDATE
Adding time to dates
Converting Dates to Character Strings
4.2 DATE and TIMESTAMP data types
From Oracle 9i, dates and times are stored as data type DATE or TIMESTAMP. The
TIMESTAMP datatype is almost identical to DATE in Oracle, but differs from it in only one way:
TIMESTAMP can represent fractional seconds. The format of TIMESTAMP is as follows:
YYY-MM-DD HH:MI:SS.nn
With a range from 0001-01-01 00:00:00 to 9999-12-31 23:59:61.999
4.3 Getting the current Date: SYSDATE
The current date is stored on the host computer for the database, and is called the system date. The
database, which interfaces with the appropriate operating system, has the capability to retrieve the
system date for its own purpose or to resolve database requests, such as queries.
Oracle uses what it calls a pseudo column, called SYSDATE, to retrieve the current date. SYSDATE
acts as any other column in a table and can be selected from any table in the database, although it is
not actually part of the tables definition.
The syntax of the SYSDATE function is as follows:
SELECT SYSDATE
FROM TABLE_NAME
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
35/95
Working with Dates and Times
AIRCOM International 35 (95)
4.4 Adding Time to Dates: INTERVAL
Intervals can be used from Oracle 9i to add periods of time to a DATETIME value. As defined by the
standard, intervals are used to manipulate the value of a DATETIME value, as in the followingexamples:
Input: DATE 1999-12-31 + INTERVAL 1 DAY
Output 2000-01-01
The INTERVAL function can be used with MINUTES, SECONDS, etc.
4.5 Adding Time to Dates without INTERVAL
In previous versions of Oracle, the same can also be accomplished by the following SQL:
Input: DATE 1999-12-31 + 1 (where 1 refers to 1 day)
Output 2000-01-01
Times are added with 1 Day as reference. The syntax for this way of adding time is as follows:
1 DAY = 1
1 HOUR = 1/24
15 MINUTES = 1/96
1 MINUTE= 1/1440 etc.
Going back to using SYSDATE, we can show the following examples:
SELECT COLUMN1
FROM TABLE_NAME
WHERE DATETIME= SYSDATE-1/24
Which will get you data from an hour ago.
4.6 Truncating dates: TRUNC
TRUNC, for dates, is the truncating of the date according to a format. Without a format, date is
truncated to 12AM (midnight). When used on dates, TRUNC will truncate SYSDATE to midnight of
a certain day with a certain precision.
The following query will return the date truncated to the 1st
day of the year
SELECT TRUNC (SYSDATE, YEAR)
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
36/95
OPTIMA Advanced User
36 (95) AIRCOM International
The next example will return the date truncated to the 1st
day of the month:
SELECT TRUNC (SYSDATE, MONTH)
To truncate to the first day of the week you would write:
SELECT TRUNC (SYSDATE, DAY)
If, in turn, you want the date truncated to the day, suppressing hours the SQL is:
SELECT TRUNC (SYSDATE, DD)
You can write similar SQL to truncate to the hour:
SELECT TRUNC (SYSDATE, HH)
Or to the minute, by using MI instead.
4.7 Converting Dates to Character strings
DATETIME values are converted to character strings to alter the appearance of output from a query. A
conversion function is used to achieve this. In Oracle, this function is the TO_CHAR function, which
works like this:
SELECT TO_CHAR(COLUMN1, DATEFORMAT)
FROM TABLE1
Example, this query:
SELECT TO_CHAR(COLUMN1, dd MONTH, yyyy)
FROM TABLE1
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
37/95
Working with Dates and Times
AIRCOM International 37 (95)
4.8 Session Summary Checklist
This checklist has been provided as a self-assessment of the objectives stated at the beginning of the
session.
Please tick all objectives covered in this Session:
DATE and TIMESTAMP data types
Getting the current date: SYSDATE
Adding time to dates
Converting dates to character strings
Additional Notes:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
38/95
OPTIMA Advanced User
38 (95) AIRCOM International
5 Joining Tables and Sub-Queries
5.1 Objectives of this session
During this session you will learn about:
Selecting data from multiple tables (Joins)
Types of Joins
Sub-Queries
5.2 Selecting data from multiple tables (Joins)
Having the capability to select data from multiple tables is one of SQLs most powerful features.
Without this capability, the entire relational database concept would not be feasible. This is called a
Join: A join combines two or more tables to retrieve data from them. Single-table queries are
sometimes quite informative, but in the real world the most practical queries are those whose data is
acquired from multiple tables within the database.
Every relational database is broken into smaller, more manageable tables for simplicity and the sake ofoverall management ease. As tables are divided into smaller tables, the related tables are created with
common columns: the primary keys. These keys are used to join related tables to one another.
To join tables, the WHERE clause is used. Several operators can be used to join tables, such as =, ,
< >, etc. However, the most common operator is the equal symbol.
5.3 Types of Joins
There are several types of joins. These are:
EQUIJOINS
OUTER JOINS
SELF JOINS
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
39/95
Joining Tables and Sub-Queries
AIRCOM International 39 (95)
5.3.1 EQUIJOINS
Perhaps the most used and important of the joins is the EQUIJOIN, also called INNER JOIN. The
EQUIJOIN joins two tables with a common column in which each is usually the primary key.
The syntax for an EQUIJOIN is:
SELECT TABLE1.COLUMN1, TABLE2.COLUMN2
FROM TABLE1, TABLE2 [,TABLE3 ]
WHERE TABLE1.COLUMN_NAME = TABLE2.COLUMN_NAME
[ AND TABLE1.COLUMN_NAME = TABLE3.COLUMN_NAME ]
Notice that each column in the SELECT clause is preceded by the associated table name in order to
identify each column. This is called qualifying columns in a query. Qualifying columns is onlynecessary for columns that exist in more than one table referenced by a query. It is normally
recommended to qualify all columns for consistency and to avoid any questions when debugging or
editing the SQL code.
5.3.2 OUTER JOINS
An OUTER JOIN is used to return all rows that exist in one table, even though corresponding rows do
not exist in the joined table. The (+) symbol is used to denote an OUTER JOIN in a query. The (+) isplaced at the end of the table name in the WHERE clause. The table with the (+) should be the table
that does not have matching rows.
The syntax for an OUTERJOIN is:
SELECT TABLE1.COLUMN NAME, TABLE2.COLUMN_NAME
[ TABLE3.COLUMN_NAME ]
FROM TABLE1, TABLE2 [,TABLE3 ]
WHERE TABLE1.COLUMN_NAME [ (+) ] = TABLE2.COLUMN_NAME [ (+) ]
[ AND TABLE1.COLUMN_NAME [ (+) ] = TABLE3.COLUMN_NAME ] [ (+) ]
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
40/95
OPTIMA Advanced User
40 (95) AIRCOM International
5.3.3 SELF JOINS
The SELF JOIN is used to join a table to itself, as if the table were two tables, by temporarily
renaming at least one table in the SQL statement. The syntax is as follows:
SELECT A.COLUMN NAME, B.COLUMN_NAME [,C.COLUMN_NAME]
FROM TABLE1 A, TABLE2 B [,TABLE3 C ]
WHERE A.COLUMN_NAME [ (+) ] = B.COLUMN_NAME [ (+) ]
[ AND A.COLUMN_NAME [ (+) ] = C.COLUMN_NAME ] [ (+) ]
SELF JOINS are useful when all the data you want to retrieve resides in one table, but you must
somehow compare records in the table to other records in the table.
5.3.4 Using a BASE Table to JOIN
When you need to retrieve data from two tables that do not have a common column to join you need a
BASE table. A BASE table is one that has a common column or columns to both tables to join on.
The syntax for using a BASE table is:
SELECT A.COLUMN_NAME, B.COLUMN_NAME
FROM TABLE1 A, TABLE2 B, TABLE3 C
WHERE A.COLUMN_NAME = C.COLUMN_NAME
AND B.COLUMN_NAME = C.COLUMN_NAME
5.4 Subqueries
A subquery us a query embedded within the WHERE clause of another query to further restrict the
data returned by the query. A subquery is also known as a nested query.
A subquery can sometimes be used in place of a join operation by indirectly linking data between the
tables based on one or more conditions.
When a subquery is used in a query, the subquery is resolved first, and the main query is resolved
according to the conditions(s) resolved by the subquery. In other words, the results of the subquery are
used to process expressions in the WHERE clause of the main query.
The subquery can be used either in the WHERE clause or the HAVING clause of the main query.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
41/95
Joining Tables and Sub-Queries
AIRCOM International 41 (95)
There are a few rules that subqueries must follow:
Subqueries must be enclosed within parentheses
A subquery can have only one column in the SELECT clause, unless multiple columns are inthe main query for the subquery to compare its selected columns.
An ORDER BY clause cannot be used in a subquery, although the main query can use it. TheGROUP BY can be used to perform the same function.
The BETWEEN operator cannot be used with a subquery, however, the BETWEEN operatorcan be used within the subquery.
The syntax for a subquery is as follows:
SELECT COLUMN_NAME
FROM TABLE
WHERE COLUMN_NAME = (SELECT COLUMN_NAME
FROM TABLE
WHERE CONDITIONS)
Subqueries are frequently used to place conditions on a query when the exact conditions are unknown.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
42/95
OPTIMA Advanced User
42 (95) AIRCOM International
5.5 Session Summary Checklist
This checklist has been provided as a self-assessment of the objectives stated at the beginning of the
session.
Please tick all objectives covered in this Session:
Selecting data from multiple tables
Types of Joins
Sub- Queries
Additional Notes:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
43/95
Other SQL statements and Performance Issues
AIRCOM International 43 (95)
6 Other SQL statements and PerformanceIssues
6.1 Objectives of this session
During this session you will learn about:
Miscellaneous Character Functions (DECODE, ROUND, NVL)
Using the LIKE operator and Wildcards
Avoiding the OR operator
Avoiding the HAVING clause
Avoiding large sorting operations
6.2 Miscellaneous Character Functions
Character functions are functions used to represent strings in SQL in alternative formats to how they
are stored in the table. Probably the two most used character functions in Optima SQL are DECODEand NVL. They are explained next:
6.2.1 DECODE
DECODE is used to search a string for a value or string, and if the string is found, an alternative string
is displayed as part of the query results.
The syntax for a DECODE function is as follows:
DECODE ( COLUMN NAME, SEARCH1, RETURN1, [ SEARCH2, RETURN2, DEFAULT
VALUE ] )
Example:
SELECT CITY,
DECODE (CITY, MADRID, MAD, BARCELONA, BAR, OTHER)
FROM ERICSSON3G.CELLCFG;
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
44/95
OPTIMA Advanced User
44 (95) AIRCOM International
The DECODE function is used very frequently in SQL to avoid division by zero errors. An example of
how it can be used for this purpose is shown next:
DECODE(SUM(PMTOTNORRCCONNECTREQCS A+PMTOTNORRCCONNECTREQPSB),0,0,
ROUND((1-SUM(PMTOTNORRCCONNECTREQCSSUCC C+PMTOTNORRCCONNECTREQPSSUCC D)/SUM(PMTOTNORRCCONNECTREQCSA+PMTOTNORRCCONNECTREQPS B))*100,2)) RRC_ESTAB_FR,
The way the DECODE function works in this SQL is like this: If the sum of A+B is 0, then
DECODE will make the whole expression inside parentheses 0, else, it will proceed with the
expression that starts with the ROUND statement. The end result will be called RRC_ESTAB_FR.
6.2.2 CASE
The CASE expression is a more flexible version of the DECODE function. In its simplest form it is
used to return a value when a match is found. The CASE expression syntax is similar to an IF-THEN-
ELSE statement. Oracle checks each condition starting from the first condition (left to right). When a
particular condition is satisfied (WHEN part) the expression returns the tagged value (THEN part). If
none of the conditions are matched, the value mentioned in the ELSE part is returned. The ELSE part
of the expression is not mandatory. The CASE expression will return null if nothing is satisfied.
The syntax of the CASE expression is as follows:
SELECT COLUMN1,
(CASE COLUMN2
WHEN THEN
WHEN THEN
...
ELSE
END ) COLUMN_ALIAS
For example:
SELECT DATE, CELL,
(CASE STATUS_FLAG
WHEN 10 THEN 'Operational'
WHEN 20 THEN 'Planned'
WHEN 30 THEN 'Off'
ELSE 'Unknown'
END) STATUS
FROM ERICSSON3G.CELLCFG
ORDER BY CELL;
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
45/95
Other SQL statements and Performance Issues
AIRCOM International 45 (95)
A more complex version is the searched CASE expression, where a comparison expression is used to
find a match. In this form the comparison is not limited to a single column, as shown next:
SELECT DATE, CELL,
(CASEWHEN TRAFFIC < 1000 THEN 'Low'
WHEN TRAFFIC BETWEEN 1000 AND 3000 THEN 'Medium'
WHEN TRAFFIC > 3000 THEN 'High'
ELSE 'N/A'
END) TRAFFIC_CAT
FROM ERICSSON3G.CELLCFG
ORDER BY TRAFFIC;
6.2.3 ROUND
The ROUND function, as shown in the previous SQL statement, will round the result of the whole
operation between parentheses to a number of decimal places, 2 in the example above.
The syntax for a ROUND function is as follows:
ROUND (COLUMN NAME, PRECISION)
6.2.4 NVL
The NVL function is used to return data from one expression if another expression is NULL. NVL can
be used with most data types; however, the value and the substitute must be of the same type.
The syntax for NVL is:
NVL (VALUE, SUBSTITUTION)
Example:
SELECT NVL (TRAFFIC, 0)
FROM ERICSSON3G.CELLSTATS;
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
46/95
OPTIMA Advanced User
46 (95) AIRCOM International
6.3 Performance Issues
SQL tuning is the process of optimising the SQL statements so that they obtain the desired results in
the most efficient way. There are several steps to SQL tuning:
Formatting SQL statements for readability
Ordering tables in the FROM clause
Order of the most restrictive conditions in the WHERE clause
Using the LIKE operator and Wildcards
Avoiding the OR operator
Avoiding the HAVING clause
Avoiding large sort operations
We will look into each of these steps in more detail.
6.3.1 Formatting SQL statements for readability
The neatness of an SQL statement does not affect the performance, however, it is good practice to
follow some basic rules of readability so that it is easy to debug and optimise the statements. Some
suggestions include:
Always begin a new line with each clause in the statement
Use tabs or spaces for indentation when arguments of a clause exceed one line
Use tabs and spaces consistently
Use table aliases to avoid clutter
6.3.2 Ordering tables in the FROM clause
List smaller tables first and larger tables last. This has been found to be more efficient.
6.3.3 Order of the most restrictive conditions
The most restrictive condition is the one which returns the least number of records. It is also the
driving factor when it comes to performance. The goal is to place the most restrictive condition first so
that a smaller subset of data is returned, reducing the querys overhead.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
47/95
Other SQL statements and Performance Issues
AIRCOM International 47 (95)
6.3.4 Using the LIKE operator and Wildcards
The LIKE operator is a useful tool that is used to place conditions on a query in a flexible manner. The
placement and use of wildcards in a query can eliminate many possibilities of data that should be
retrieved. Wildcards are very flexible for queries that search for similar data
6.3.5 Avoiding the OR operator
Rewriting the SQL statement using the IN predicate instead of the OR operator consistently and
substantially improves the data retrieval speed.
Example, using the OR operator:
SELECT CELLID, CELLNAMEFROM ERICSSON3G.CELLCFG
WHERE CITY = MADRID
OR CITY = BARCELONA
OR CITY = ZARAGOZA;
Example, using the IN predicate:
SELECT CELLID, CELLNAME
FROM ERICSSON3G.CELLCFG
WHERE CITY IN (MADRID, BARCELONA, ZARAGOZA);
6.3.6 Avoiding the HAVING clause
Using the HAVING clause causes the SQL optimiser extra work. If possible, SQL statements should
be written without the use of the HAVING clause.
6.3.7 Avoiding large sort operations
Large sort operations mean the use of the ORDER BY, GROUP BY and HAVING clauses. Subsets of
data must be stored in memory or disk whenever sort operations are performed. Whenever possible, itis best to schedule queries with large sorts as periodic batch processes during off-peak database usage.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
48/95
OPTIMA Advanced User
48 (95) AIRCOM International
6.4 Session Summary Checklist
This checklist has been provided as a self-assessment of the objectives stated at the beginning of the
session.
Please tick all objectives covered in this Session:
Miscellaneous Character Functions (DECODE, ROUND, NVL)
Using the LIKE operator and Wildcards
Avoiding the OR operator
Avoiding the HAVING clause
Avoiding large sorting operations
Additional Notes:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
49/95
SQL Exercises
AIRCOM International 49 (95)
7 SQL Exercises
7.1 Objectives of this session
During this session you will learn about:
Creating Simple Queries
Creating Queries that use operators
Creating Queries that use summaries and grouping
Creating Queries that use dates and time
Creating Queries with Joins and Sub queries
Creating Queries that use ROUND, DECODE, CASE and NVL
7.2 Simple Queries
Note: As you will not be using any conditions for the first two queries, the amount of data returned canbe very large. Be sure to use a table with a manageable size, such as Configuration tables or
Summary tables.
7.2.1 SELECT FROM
Create a query using the SELECT statement to retrieve 2 or 3 columns from a table.
7.2.2 SELECT DISTINCT
Create a query using the SELECT DISTINCT statement to avoid getting duplicate data from 2 or 3
columns from a table.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
50/95
OPTIMA Advanced User
50 (95) AIRCOM International
7.2.3 WHERE
Create a query using the WHERE condition to restrict the number of records returned. Get this data
from 2 or 3 columns from a table.
7.2.4 ORDER BY
Refine the query created in the WHERE exercise by using the ORDER BY clause to sort the output.
Sort a column first in Ascending order and then in Descending order. Also, try sorting an
alphanumeric column and a numeric column.
7.2.5 ORDER BY, with integers as identifiers
Continuing with the query from the ORDER BY exercise, sort the different columns in ascending
order by using integers as identifiers.
7.2.6 Column Aliases
Continue with the query from the previous exercise, this time providing aliases for the different
columns.
7.3 Queries using operators
Use the same table for these queries to enable comparisons in the data returned. Select columns with
numerical data except where not appropriate.
7.3.1 Comparison Operators
Create a series of queries using the comparison operators introduced earlier in the course. Use theequal to, not equal to, greather than and less than operators on simple SELECT-FROM-WHERE
queries.
7.3.2 Logical Operators: IS NULL
Create a couple of queries using the IS NULL operator. Find NULL data by using the IS NULL
operator correctly, then use the WHERE COLUMN= NULL statement and compare outputs.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
51/95
SQL Exercises
AIRCOM International 51 (95)
7.3.3 Logical Operators: BETWEEN
Create a query using the BETWEEN operator.
7.3.4 Logical Operators: IN
Create a query using the IN operator.
7.3.5 Logical Operators: LIKE
Create a couple of queries using the LIKE operator. Use the two wildcards available for the LIKEoperator to observe their results.
7.3.6 Conjunctive Operators: AND
Create a couple of queries using the AND operator in the WHERE condition. Observe the output.
7.3.7 Conjunctive Operators: OR
Create a couple of queries by using the OR operator in place of the AND operator from the previous
queries. Observe and compare the output.
7.3.8 Arithmetic Operators
Create a few queries using the different arithmetic operators on numeric columns. Add, substract, etc
two columns. Use Aliases for the output column.
7.4 Queries using Summaries and GroupingThe following exercises explore the use of Aggregate funtions, Summaries and Grouping.
7.4.1 Aggregate Functions: COUNT
Find out the number of records in a small table by using the COUNT function.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
52/95
OPTIMA Advanced User
52 (95) AIRCOM International
7.4.2 Aggregate Functions: SUM
Create a couple of queries using the SUM function. Find out the sum results for a few numerical
columns. Do not group results at this stage.
7.4.3 Aggregate Functions: MIN, MAX and AVERAGE
Create a set of queries using the MIN, MAX and AVERAGE functions. Find out the Minimum,
Maximum and AVERAGE values for a few numerical columns.
7.4.4 GROUP BY with Aggregate functions
Create a query selecting several columns, use aggregate functions such as SUM on most of them but
not on all. Group the data using the GROUP BY clause.
7.4.5 HAVING
Continuing with your GROUP BY query, add some further conditions by using the HAVING
clause.
7.5 Queries using Dates and Time
The following exercises explore the use of Dates and Time.
7.5.1 SYSDATE
Create a simple query to get the current date and time.
7.5.2 INTERVAL
Add an interval of 1 day to your SYSDATE query. Repeat by adding other intervals, like 1 hour and
1 minute.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
53/95
SQL Exercises
AIRCOM International 53 (95)
7.5.3 Adding dates without using INTERVAL
Using your SYSDATE query, substract several time intervals such as 1 hour, 15 minutes and 1
minute.
7.5.4 Using the TRUNC ( ) function
Use the TRUNC function to truncate the SYSDATE and observe the resulting date and time.
7.5.5 Selecting data using BETWEEN and SYSDATE
Create a query where you select data located in between certain time periods. Use the BETWEEN
clause and select data between 1 hour ago and 1:15 hours ago.
7.6 Joins and Subqueries
The following exercises explore the use of EQUIJOINS and Subqueries.
7.6.1 EQUIJOINS
Create a query that joins two tables by using the WHERE condition and by joining them using the
primary key, in other words, by using an EQUIJOIN.
7.6.2 Sub Queries
Create a query that uses a sub query to process data before its used in a main query.
7.7 ROUND, DECODE and NVL
The following exercises explore the use of ROUND, DECODE and NVL.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
54/95
OPTIMA Advanced User
54 (95) AIRCOM International
7.7.1 ROUND
Create a query that retrieves data from a numeric column. Use the ROUND function to round decimals
to a precision of 2.
7.7.2 DECODE
Create a query that avoids a division by 0 error by using the DECODE function.
7.7.3 CASE
Create a query using the CASE expression to account for different levels of numerical data.
7.7.4 NVL
Create a query that finds Null values for a column and substitutes them with 0.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
55/95
SQL Exercises
AIRCOM International 55 (95)
7.8 Session Summary Checklist
This checklist has been provided as a self-assessment of the objectives stated at the beginning of the
session.
Please tick all objectives covered in this Session:
Creating Simple Queries
Creating Queries that use operators
Creating Queries that use summaries and grouping
Creating Queries that use dates and times
Creating Queries that include sub queries
Creating Queries that avoid division by zero errors and Null values
Additional Notes:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
56/95
OPTIMA Advanced User
56 (95) AIRCOM International
8 Creating OPTIMA Modules
8.1 Objectives of this session
During this session you will learn about:
Creating Optima Module
Defining queries using the Query Builder
Defining queries using the SQL tab
Editing and Deleting Modules
8.2 Creating Modules
Module creation can only be carried out by those with Advanced_user or Administrator permissions.
From within the Module Explorer window, clicking on the New Module button will permit access to
the Optima Module Maker window.
Alternatively, you can right click in any area of the Module Explorer and from the menu that appears
select New Module. This option is also available through the File Menu.
Within the Module Information tab, enter the module name together with a description.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
57/95
Creating OPTIMA Modules
AIRCOM International 57 (95)
The Module Definition tab allows the user to define the module information, using the Data Explorer
window, which is launched by clicking on the Edit Tree SQL button. In this first step you will
create the Network element tree which can subsequently be used to configure SQL statements on each
network element selected.
Important Note:
When creating a Network element tree you should choose your elements from database tables whichallow smaller querying, making the return of data faster. Your statement should also return datawith no duplicates thereby making the operation of the statement simpler.
In order to meet both of the above criteria it is strongly recommended that you query theConfiguration tables. The addition of a DISTINCT or WHERE command will also preventduplicates being returned if you choose to query other database tables.
8.2.1 Data Explorer Window
The Database or Data Explorer window has two main functions:
1. The easy selection of tables and views within a schema browser to see column details and data.
2. A facility to drag and drop tables and views from a schema browser onto a query builder, enablingeasy SQL query building.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
58/95
OPTIMA Advanced User
58 (95) AIRCOM International
The Data Explorer window is split into three main areas. On the left is the Schema browser, which
lists the different OPTIMA Database schemas along with the tables (counters) and views. Details of
database tables or views are displayed in the top right of the window, in column or data form
(depending on the tab selected). Below this area is the Query Designer area, consisting of four maintabs (Builder, SQL, Filters and Preview), which will be covered in more detail later.
In addition the data explorer provides a counter search function that highlights tables containing the
counter of interest. This facility can be found under the Edit heading of the Data Explorer toolbar, or
by clicking the Find Counter button .
Having entered the counter name (i.e. ERLANG), click on the Find next button to initialise the
search function, the first table containing the counter of interest will then be highlighted:
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
59/95
Creating OPTIMA Modules
AIRCOM International 59 (95)
Database tables viewed within the data explorer can be grouped into logical categories for ease of
reference; this task is performed by your OPTIMA Administrator.
8.2.2 Query Builder
The Query Builder has been incorporated into OPTIMA for users who have little experience or
expertise in using SQL. Using the Query Builder, SQL statements can be easily built for use within
individual modules, or within the Data Explorer to view data from the OPTIMA Database.
8.3 Defining a query using the Builder Tab
A query will return data from OPTIMAs database tables, and within the Data Explorer you can view
the data returned from the database. If you are unfamiliar with SQL the Builder tab can be used to
create the query.
Note: The Builder tab will only be active if your OPTIMA database is Oracle 9i or above.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
60/95
OPTIMA Advanced User
60 (95) AIRCOM International
Having selected the Builder tab within the Data Explorer you can double-click, or drag and drop
tables from the schema area into the area within the Builder tab. Alternatively tables can be removed
from the Builder tab area by closing the table window displayed.
Columns to be included in the query can be selected by clicking in their respective boxes. The SQLstatement is created automatically according to the order in which columns were selected.
Alternatively clicking the check-box next to the table heading includes all columns in the query.
Selecting individual columns from the selected table Selecting all columns within the selected table
To add a link between two tables, you select a column heading in one table and while holding down
the left mouse button drag it over to a column heading in another table.
However, a link will not be made if the two columns cannot be linked. To remove a link, right click,and from the menu that appears select Delete link.
Double-clicking on a link sets the link type, which by default are inner links. Therefore only rows
with matching values in the linked columns will be displayed when the query is run.
Dragging tables and selecting columns within the Builder tab is in essence only the first stage in
creating the query, and having selected the columns to be included in the query the tabs below the
Builder tab area are used to define the query itself.
There are four tabs, each having a specific purpose as described below:
Criteria: Used to construct the query Where clauses in which conditions are added.More than one criterion can be added.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
61/95
Creating OPTIMA Modules
AIRCOM International 61 (95)
Selection: Provides a grid which lists the selected table columns. By default single rowvalues will be returned for each selected table column, but by double clicking
within the Aggregate column, a list of aggregate functions will be displayed,
from which a selection can be made.
If an aggregate function is included the Query Builder will automatically modify
the SQL statement, by adding the appropriate Group By clause.
Grouping criteria: If you want a Having clause in your query, this can be defined within this area.
Sorting: Setting the Sort order of the data is done within this area. Each columnreturned in the query is listed in a panel on the left, from which the columns to
be ordered by are selected. Functionality is provided to allow column position to
be changed, thus changing the sort order within the Order by clause (in either
ascending or descending order).
Having entered the relevant information into the above tabs, you can preview the query by clicking on
the SQL tab.
The SQL tab provides an area in which the SQL generated by the Query Builder is displayed. For
improved usability the Oracle Keywords will be coloured blue.
Clicking on the Filters tab enables you to add filters to the query. This will allow data filtering at
runtime but can also be useful for testing and running ad-hoc queries.
If a Date Filter and Filter field is required, the appropriate value must be highlighted in the respective
field area, before selecting it using the > button.
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
62/95
OPTIMA Advanced User
62 (95) AIRCOM International
When these two parameters are used within the query, the placeholders %DATE and %FILTER are
automatically placed in the SQL within the main WHERE clause. In the example above, theERICSSON2G.CELLSTATS.SDATE date parameter field has been selected, and the %DATE
placeholder will be replaced when the query is run by a date clause.
Selecting the Preview tab will allow the user to preview the results of an executed SQL query,
displayed as an OPTIMA Grid. However, you must first click on the Execute Query buttonbeforepreviewing the results.
Depending on the Filter configuration, conducted within the Filter tab, you may be prompted to enter a
date range of to choose a filter. This is done within the Parameter Input window, shown below.
Choosing a Filter Selecting a Date range
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
63/95
Creating OPTIMA Modules
AIRCOM International 63 (95)
Having entered the required information within the Parameter Input window, you should now be ableto see the results of the query.
8.4 Defining a query using the SQL Tab
If you are confident in the use of SQL, you can bypass the functionality of the Builder tab and use the
SQL tab to create your SQL query. However, if you manually define your SQL query the options
available within the Builder tab will be disabled.
Having selected the SQL tab users will be provided with an area in which to write their own database
query, or manually edit an existing query.
To assist in the creation of SQL queries an Oracle Commands pane is provided which contains a list
of SQL Templates and acceptable Oracle keywords, functions and filter placeholders. These can be
8/3/2019 PS TR PDF E121 V6.1 Optima Advanced User
64/95
OPTIMA Advanced User
64 (95) AIRCOM International
used by dragged and dropping into the SQL text area. You can also use the Schema Browser area to
drag and drop table and column names into the SQL text area.
Within the SQL tab a separate toolbar exists that enables you to cut, copy, paste and delete SQL
together with an undo function with respect to the last SQL change. An SQL Expression Builder isalso available via the toolbar, but also through a right-click pop-up menu and provides a user-friendly
interface for building Oracle expressions using drop down menus.
Having built an Oracle expression the OK button can be used to insert the expression into the SQL
query being written.
If you have not already added filters manually to your SQL query, you can use the functionality within
the Filters tab to do so.
The query can be run against the OPTIMA database at any time using the Execute Query button,
with the results being displayed within the Preview tab.
8.5 Using SQL
The purpose of the SQL statement used within a module is to find specific data within the OPTIMA
database. It is advisable that OPTIMA_Advanced_Users and OPTIMA_Administrators are
comfortable in using SQL before undert