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 content: Programming with SQL 1 Create queries to retrieve information a Describe the capabilities of SQL SELECT statements b Describe basic SELECT statements c Describe the limiting of rows retrieved by a query d Describe the sorting of rows retrieved by a query e Describe various categories of functions available in SQL f Describe the use of character, number, and date functions in SELECT statements g Describe the use of conversion functions Describe the use of SELECT statements for projection, selection and joining. 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 WHERE clause Comparison operators Logical operators NULL condition Operator precedence ORDER BY clause To include the following functions: Single row and multiple row Character, number, date and conversion 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 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 282 OCR Level 3 Certificate/Diploma for IT Professionals
h Use conditional expressions i j Use SELECT statements to access data from more than one table using equality and non-equality joins Describe how to view data that generally does not meet a join condition by using outer joins CASE DECODE Cartesian product Oracle specific syntax (equijoin, nonequijoin) ANSI standard syntax (CROSS JOIN, NATURAL JOIN, JOIN USING, JOIN ON) 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 HAVING clause. rows o Define subqueries and the types of problem that they can solve p Identify the types of subqueries q Use single-row and multiple-row subqueries 2 Insert, update and delete data in a database a Describe how to add a new row into a table b Describe how to remove a row from a table Subquery syntax Effect of NULL values in a subquery Single row subqueries Multiple row subqueries Single row operators Multiple row operators (IN, ANY, ALL) INSERT statement Inserting NULL values Explicit default values Date values Copying data from another table Inserting into a subquery DELETE statement Deleting rows based on another table OCR Level 3 Certificate/Diploma for IT Professionals 283
c Describe how to change the data in a table UPDATE statement Using a subquery to update two columns Updating rows based upon another table Integrity constraint errors d Describe how to conditionally insert or update data in a table 3 Create, modify and remove database objects a Describe the main database objects b Describe the creation of tables c Describe the use of data types that can be used when specifying column definitions d Use statements to alter table definitions e Use statements to drop, rename, and truncate tables MERGE statement. Objects to include: Table View Sequence Index Synonym Table and column naming restrictions CREATE TABLE Referencing another users table DEFAULT values Creating a table using a subquery 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) ALTER TABLE statements (ADD, MODIFY, DROP COLUMN, SET UNUSED). DROP TABLE RENAME TRUNCATE TABLE f Use constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY CHECK g Describe the creation and maintenance of constraints Constraints to include: Table and column level definitions Naming conventions Disabling, enabling and cascading 284 OCR Level 3 Certificate/Diploma for IT Professionals
h Describe a view Simple and complex views i j k l Use statements to create, replace the definition of, and drop a view Describe the retrieval of data through a view Describe how to insert, update, and delete data through a view Use and create an inline view m Use of top-n analysis n Use statements to create and maintain use of sequences o Create and maintain indexes p Create private and public synonyms 4 User access control a Create users b Create roles to ease set up and maintain security of the model CREATE OR REPLACE DROP VIEW TO include: CREATE SEQUENCE ALTER SEQUENCE DROP SEQUENCE NEXTVAL and CURVAL pseudocolumns REATE INDEX DROP INDEX Automatic and manual creation of indexes Function based indexes CREATE SYNONYM DROP SYNONYM CREATE USER statement CREATE ROLE statement c Grant and revoke object privileges GRANT and REVOKE statements system and 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