Unit 43: Programming with SQL

Unit 43:
Programming with SQL
Learning Outcomes
A candidate following a programme of learning leading to this unit will be able to:
•
Create queries to retrieve information from relational databases using both ANSI standard
and Oracle specific syntax
•
Understand the application of Data Manipulation Language to insert, update and delete data
held in a database
•
Understand the application of Data Definition Language to create, modify and remove
Tables, Views, Indexes, Synonyms and Sequences
•
Understand the basics of user access control.
NB Before starting this unit please refer to the Vendor website for up-to-date specifications,
examination objectives and availability.
OCR Level 3 Certificate/Diploma for IT Professionals
281
Unit 43: Programming with SQL
Unit content: Programming with SQL
Assessment Objectives
Knowledge, Skills and Understanding
1 Create queries to retrieve information
a Describe the capabilities of SQL SELECT
statements
Describe the use of SELECT statements for
projection, selection and joining.
b Describe basic SELECT statements
To include:
• Syntax of basic select statements
• Selecting a column and/or selecting all
columns
• Mathematical and concatenation operators
• Use of parenthesis
• Literal character strings
• DISTINCT keyword
c
To include:
• WHERE clause
• Comparison operators
• Logical operators
• NULL condition
• Operator precedence
Describe the limiting of rows retrieved by a
query
d Describe the sorting of rows retrieved by a
query
ORDER BY clause
e Describe various categories of functions
available in SQL
To include the following functions:
• Single row and multiple row
• Character, number, date and conversion
f
To include functions:
• Case manipulation functions (LOWER,
UPPER, INITCAP)
• Character manipulation functions (CONCAT,
SUBSTR, LENGTH, INSTR, LPAD/RPAD,
TRIM, REPLACE)
• Number functions (ROUND, TRUNC, MOD)
• Date functions (MONTHS_BETWEEN,
ADD_MONTHS, NEXT_DAY, LAST_DAY,
ROUND, TRUNC, SYSDATE)
• Date arithmetic
• Default date format
Describe the use of character, number, and
date functions in SELECT statements
g Describe the use of conversion functions
282
To include:
• Implicit data type conversion
• Explicit data type conversion (TO_CHAR,
TO_NUMBER, TO_DATE)
• Elements of the date format model
• Null conversions (NVL, NVL2, NULLIF)
• COALLESE
OCR Level 3 Certificate/Diploma for IT Professionals
Unit 43: Programming with SQL
Assessment Objectives
Knowledge, Skills and Understanding
h Use conditional expressions
To include:
• CASE
• DECODE
i
Use SELECT statements to access data
from more than one table using equality and
non-equality joins
To include:
• Cartesian product
• Oracle specific syntax (equijoin, nonequijoin)
• ANSI standard syntax (CROSS JOIN,
NATURAL JOIN, JOIN USING, JOIN ON)
j
Describe how to view data that generally
does not meet a join condition by using outer
joins
To include:
• Oracle specific syntax (outer joins using (+))
• ANSI standard syntax (LEFT/RIGHT/FULL
OUTER JOIN)
k
Use a self join to join a table to itself
l
Use the available group functions
AVG, COUNT, MAX, MIN, STDDEV, SUM,
VARIANCE.
m Describe how to group data
GROUP BY clause.
n Describe how to include or exclude grouped
rows
HAVING clause.
o Define subqueries and the types of problem
that they can solve
To include:
• Subquery syntax
• Effect of NULL values in a subquery
p Identify the types of subqueries
To include:
• Single row subqueries
• Multiple row subqueries
q Use single-row and multiple-row subqueries
To include:
• Single row operators
• Multiple row operators (IN, ANY, ALL)
2 Insert, update and delete data in a database
a Describe how to add a new row into a table
To include:
• INSERT statement
• Inserting NULL values
• Explicit default values
• Date values
• Copying data from another table
• Inserting into a subquery
b Describe how to remove a row from a table
To include:
• DELETE statement
• Deleting rows based on another table
OCR Level 3 Certificate/Diploma for IT Professionals
283
Unit 43: Programming with SQL
Assessment Objectives
Knowledge, Skills and Understanding
c
To include:
• UPDATE statement
• Using a subquery to update two columns
• Updating rows based upon another table
• Integrity constraint errors
Describe how to change the data in a table
d Describe how to conditionally insert or
update data in a table
MERGE statement.
3 Create, modify and remove database objects
a Describe the main database objects
Objects to include:
• Table
• View
• Sequence
• Index
• Synonym
b Describe the creation of tables
To include:
• Table and column naming restrictions
• CREATE TABLE
• Referencing another users table
• DEFAULT values
• Creating a table using a subquery
c
To include:
• Standard data types (VARCHAR2, CHAR,
NUMBER, DATE, LONG, CLOB, BLOB,
BFILE, ROWID)
• Basic date time data types (TIMESTAMP
and variations, INTERVAL YEAR TO
MONTH, INTERVAL DAY To SECOND)
Describe the use of data types that can be
used when specifying column definitions
d Use statements to alter table definitions
ALTER TABLE statements (ADD, MODIFY,
DROP COLUMN, SET UNUSED).
e Use statements to drop, rename, and
truncate tables
To include:
• DROP TABLE
• RENAME
• TRUNCATE TABLE
f
To include:
• NOT NULL
• UNIQUE
• PRIMARY KEY
• FOREIGN KEY
• CHECK
Use constraints
g Describe the creation and maintenance of
constraints
284
Constraints to include:
• Table and column level definitions
• Naming conventions
• Disabling, enabling and cascading
OCR Level 3 Certificate/Diploma for IT Professionals
Unit 43: Programming with SQL
Assessment Objectives
Knowledge, Skills and Understanding
h Describe a view
•
i
Use statements to create, replace the
definition of, and drop a view
To include:
• CREATE OR REPLACE
• DROP VIEW
j
Describe the retrieval of data through a view
k
Describe how to insert, update, and delete
data through a view
l
Use and create an inline view
Simple and complex views
m Use of top-n analysis
n Use statements to create and maintain use
of sequences
TO include:
• CREATE SEQUENCE
• ALTER SEQUENCE
• DROP SEQUENCE
• NEXTVAL and CURVAL pseudocolumns
o Create and maintain indexes
To include:
• REATE INDEX
• DROP INDEX
• Automatic and manual creation of indexes
• Function based indexes
p Create private and public synonyms
To include:
• CREATE SYNONYM
• DROP SYNONYM
4 User access control
a Create users
CREATE USER statement
b Create roles to ease set up and maintain
security of the model
CREATE ROLE statement
c
To include:
• GRANT and REVOKE statements
• system and object privileges
Grant and revoke object privileges
d Describe the creation of database links
Assessment
This unit will be assessed by an electronic examination set and externally marked by Oracle.
Examinations take the form of multiple choice and multiple answer objective tests.
The examination is administered on a computer at an authorised Oracle Academy.
Notes for Tutors
Knowledge for this examination may be gained through the official Oracle Academy: Introduction to
Computer Science and Business course: Database Design and Programming.
OCR Level 3 Certificate/Diploma for IT Professionals
285