Database Tutorial

Course Tutorial Site

Site Admin

CIT325: Lab 12 Instructions

without comments

Lab #12: Oracle Assignment

Objectives

The lab is designed to teach you how to work with Oracle’s Dynamic SQL (NDS). NDS allows you to write PL/SQL blocks that dynamically generate other SQL statements or PL/SQL blocks.

  • Learn how to create and run a dynamically generated SQL statement.
  • Learn how to create and run a function that returns a result from a dynamically generated SQL statement.
  • Learn how to work with bind variables.

Business Scenario

Sometimes you have use-cases that require your program’s behaviors to change dynamically at runtime. Oracle provides Native Dynamic SQL (NDS) and an older DBMS_OUTPUT package for these type of use-cases. NDS is the easier to use solution and lets you manage the following use-cases:

  • Creating dynamic SQL statements as strings to run in your code blocks.
  • Creating dynamic SQL statements as strings that accept positionally bound variables, known as bind variables. They can be:

    • Traditional ANSI standard INSERT, UPDATE, MERGE, or DELETE statements that return nothing.
    • Oracle INSERT, UPDATE, MERGE, or DELETE statements that use the RETURNING INTO clause.
    • Queries that return a static column result set for one row of data.
    • Queries that return a static column result set for any number of rows of data.

  • Creating dynamic PL/SQL blocks that accept:

    • Only inputs, where the inputs may be numeric or string literal values or variables.
    • Inputs and outputs – where the inputs may only be variables because otherwise they couldn’t output results from the dynamic statement.

This lab asks you to work with creating a dynamic query that returns a static column result set for any number of rows of data. You need to use the DBMS_OUTPUT package when you want your program to return a variable number of columns or you need to convert a LONG data type to a CLOB data type.

Help Section

The following is an set of sample programs and steps that address concepts in the lab. The instructor should review these in classroom or in a Google Hangout with students. Click the Instructional Material link to see the preparation lesson material.

Students may want or need supplemental articles that let them review tips and techniques. The following is a function that checks for valid dates inside strings. You should run this type of check after you rule out a number and alphanumeric string.

There are four elements to this lab. It requires you to create:

  • An item_obj object type
  • An item_tab collection type
  • An item_list function

It is important that you develop each piece sequentially. You should also test each piece of the code as you develop them.

Lab Description

  1. [25 points] Create the item_obj object type, a item_tab collection object type, and item_list function.

    The sections cover the detailed tasks of the lab:

Written by michaelmclaughlin

December 15th, 2016 at 11:33 am

Posted in