Week 2 February 1 • PL/SQL • Creating a Form

advertisement
1
Week 2
February 1
• PL/SQL
• Creating a Form
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Coding Standards
2
• Element names (functions, objects, variables, etc.): 30character maximum length
• Uppercase letters for keywords
• Lowercase letters for user-defined elements
• 80 characters per line
– One command per line
• Comments
– Header comments: /* comment */
– Inline comments: -- comment
• Prefix object names
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
PL/SQL
Processing Language/SQL
• Procedural processing language for various Oracle tools:
– Forms
– Reports
– Graphics
• Character set
– Alphabetic, numeric and special characters
– Arithmetic and relational operators
– Others (;, ., :=, | |, --, /* */)
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
3
PL/SQL Block
4
Declaration Section
Declares variables and constants
(optional).
Executable Section
Procedural programming
Exception Section
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Defines the exception
handlers invoked for both
predefined and user-defined
exceptions (optional).
PL/SQL Block
5
Declare section
Executable
section
Exception section
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
PL/SQL
Declaration Section
• Declare variable and constant names and types
• Data types
– Character (varchar2)
– Numeric
– Date
– Boolean
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
6
Variable and Constant Declaration
7
• Defines the existence of all variables used in the procedure
...
declare
variable-name data-type;
constant-name := value;
– For example...
declare
Data types
line_count number;
product_request varchar2(10);
max_count := 20;
Constant
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
For Example...
8
declare
product_request varchar2(3);
product_descrip varchar(30);
Query assigned to “product”
price real;
cursor product is
select product_description, product_msrp from products
where manufacturer_code = product_request;
...
begin;
open product;
loop
fetch product into product_descrip, price;
...
Order of variables must match the order in the select
close product;
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Executable Section
9
• Types of statements
– Assignment
– Flow-of-control
– SQL
– Cursor
• All statements must be terminated by a semi-colon (;)
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Exception Section
10
• Instructs PL/SQL how to handle particular exceptions
exception
when exception-name then
PL/SQL statements;
when exception-name then
PL/SQL statements;
end;
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Exception Names
11
• Predefined - Defined in Oracle
– DUP_VAL_ON_INDEX (duplicate value on a unique
index)
– INVALID_NUMBER
– NO_DATA_FOUND (no rows returned)
– TOO_MANY_ROWS (multiple rows returned)
– VALUE_ERROR
• User-defined - Defined in the declarations as an exception
(data type).
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Oracle Developer
12
• Forms (interactive)
– Presenting information and entering data online
• Reports (reporting)
– Page-oriented display of information
• Graphics (charts)
– Graphic representation of data
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
13
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Forms Designer
14
• Four major components
– Object Navigator
– Layout editor
– Property palette (sheet)
– PL/SQL editor
R. Ching, Ph.D. • MIS Area • California State University, Sacramento

 Object Navigator
15
Forms module with various objects
Modules
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Modules:
• Forms
• Menu
• Libraries
• Built-in Packages
• Database Objects
Menus
16
Toolbar
Object type Hierarchy
Specifies the order in
which objects and items
are executed
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Window and Canvas Objects
17
Window
Canvas-View
Canvas-View
Four types of canvas-views:
Content, Stacked, Horizontal
Toolbar, and Vertical Toolbar
Interface Item
Boilerplate objects
(lines, images, boxes, etc.)
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Window-Canvas-Block-Items Relationship
18
Menu object
Items
PL/SQL
Block
Canvas-View
Window
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
 Layout Editor
19
Tool bar
Rulers
Tool palette
Layout work area
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
 Property Palette
Set an
object’s
attributes
Properties of the canvas
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
20
Triggers
21
Trigger
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
 PL/SQL Editor
22
Trigger
PL/SQL code
List of
triggers
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Inheriting Properties
23
Stereos to Go!
Enter
Exit
Stereos to Go!
View
Report
Graph
Exit
Class Properties
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Creating a Property Class
24
• Create a Property Class object in the parent module
• Add the property and its values
• Select the object in the child
– Under Subclass Information,
specify the property class
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Create the Property Class in the Parent
25
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Add the Properties to the Class
26
Added to the class
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Inherit the Property Class in the Child
27
 Select the object and its Property Palette
 Select Subclass Information
 Specify the object or property class name and its form
module
Property class
Parent module
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
 Menus
Menus
28
Menu
items
 File Menu
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Menu Module
29
 Menu module
 Menu object
Menu items
Five Simple Steps:
Create the menu module
Add the menu objects
Add the menu items to the menu objects
Program the items in PL/SQL
Attach the menu module to the form
module
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Why Multiple Forms?
30
• Build more functional units (forms)
– Design the form to support a narrow scope of functions
– Reduce the complexity of a single form
• Reduce the time to develop and implement an application
• Enhance maintainability of the application
(plug-and-play!)
• Promotes reusability or cloning
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Calling and Called Forms
31
• The calling form module
transfers control (calls, opens)
to the called form
 
Calling
Called
CALL_FORM(form-module-name,display,switch-menu)
– Calling form remains present
behind the called form
– Called module assumes the calling module’s menu
module
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Calling and Called Forms
32
• Upon exit of the called form,
control returns to the calling
formmodule
EXIT_FORM
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
 
Calling
Called
Calling a Form Module
33
• Create or select an item (i.e., push button) on the canvas or
in the menu module
• Program the item in the PL/SQL Editor
– Select a trigger that will activate the procedure
– Enter the CALL_FORM statement
– Compile the code
• Test the form module
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
In the PL/SQL Editor
34
Form module name
Causes Oracle Forms to keep the
default menu application of the calling
form active for the called form.
(REPLACE)
Causes Oracle Forms to clear the calling form
from the screen before drawing the called form.
HIDE is the default parameter. (NO_HIDE)
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
NEW_FORM
35
• NEW_FORM closes the calling form
Greeting Screen
NEW_FORM
Menu
Main Menu
EXIT_FORM
CALL_FORM
EXIT_FORM
Query
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
36
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Download