Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

17 Defining Simple

Procedures

Copyright © 2007, Oracle. All rights reserved.


Objectives

After completing this lesson,


you will know how to:
• Create simple reusable
procedures
• Add commands
• Provide options on your
commands
• Run your procedures

17 - 2 Copyright © 2007, Oracle. All rights reserved.


Overview of Procedures

Definition and Examples

17 - 3 Copyright © 2007, Oracle. All rights reserved.


What Is a Procedure?

Procedure: A sequence of commands executed by


database engines, the operating system, or using Oracle
Data Integrator Tools. A procedure can have options that
control its behavior.
Procedures are reusable components that can be inserted
into packages.

17 - 4 Copyright © 2007, Oracle. All rights reserved.


Procedure Examples

• Email Administrator procedure


1. Uses the “OdiSendMail” Oracle Data Integrator tool to
send an administrative email to a user. The email address
is an option.
• Clean Environment procedure
1. Deletes the contents of the /temp directory using the
“OdiFileDelete” tool.
2. Runs DELETE statements on these tables in order:
CUSTOMER, CITY, REGION, COUNTRY.

17 - 5 Copyright © 2007, Oracle. All rights reserved.


Procedure Examples

• Initialize Drive procedure


1. Connect to a network drive using either a Unix or
Windows command (depending on an option).
2. Create a /work directory on this drive.
• Email Changes procedure
1. Wait for 10 rows to be inserted into the INCOMING table.
2. Transfer all the data from INCOMING to the OUTGOING
table.
3. Dump the content of the OUTGOING table to a text file.
4. Email this text file to a user.

17 - 6 Copyright © 2007, Oracle. All rights reserved.


Using Procedures: Overview

To make a procedure:
1. Create a blank procedure
2. Add some commands
3. Add some options
4. Run the procedure

17 - 7 Copyright © 2007, Oracle. All rights reserved.


1. Creating a Procedure

17 - 8 Copyright © 2007, Oracle. All rights reserved.


How to Create a New Procedure

1. Right-click the
Procedures node under a
project.
2. Select Insert Procedure.
3. Fill in the
– Name
– Description
4. Optionally, define the
default:
– Source Technology
– Target Technology
5. Click Apply to save.

17 - 9 Copyright © 2007, Oracle. All rights reserved.


2. Adding Commands

17 - 10 Copyright © 2007, Oracle. All rights reserved.


Creating a New Command

1. Select the procedure’s


Details tab.
2. Click the Add Command
button.
3. Fill in the Name.
4. Set Ignore Errors as appropriate.
5. For the Command on Target,
select:
– Technology
– Context
– Logical Schema
– Command code (using the
Expression Editor)
6. Repeat step 5 for the
Command on Source (optional).
7. Click OK.

17 - 11 Copyright © 2007, Oracle. All rights reserved.


Arranging Steps in Order

• The Details tab shows the


steps of your procedure.
• Steps are executed
top to bottom.
– In this example, “Wait for
data in INCOMING” is
executed last.
– We need it to be executed
first.

• To rearrange steps, use


the up and down buttons.
– Now the procedure will
wait for data before attempting
the transfer.
• Make sure the order of your
steps is correct.

17 - 13 Copyright © 2007, Oracle. All rights reserved.


Which Parameters Should be Set?

The following parameters should be set in the command:


• Technology: Overrides the default technology for the
procedure.
• Logical Schema: For DBMS technologies (Jython, OS,
Oracle Data Integrator Tools do not require a schema)
• Context: If you want to ignore the execution context
• Ignore Errors: If the command must not stop the
procedure. A warning is issued only if the command
fails.

17 - 14 Copyright © 2007, Oracle. All rights reserved.


Valid Types of Commands

Some examples of the types of commands that can be


used in Oracle Data Integrator procedures:

SQL statement Executed on any DBMS technology


DELETE, INSERT, SELECT, … statements.

OS commands Executed on the Operating System technology


In OS-specific syntax using shell commands or
binary programs
Executed on the Sunopsis API technology
Oracle Data Integrator Tools Any Oracle Data Integrator tool command call.
Executed on the Jython technology.
Can call Java code or pre-compiled objects

Jython programs

17 - 15 Copyright © 2007, Oracle. All rights reserved.


More Elements

In addition, we have access to the following Oracle Data


Integrator–specific elements that can be used within the
commands:

Variables They may be specified either in substitution mode


#<variable>, or in bind mode :<variable>

Sequences They may be specified either in substitution mode


#<sequence>, or in bind mode :<sequence>

User functions Used like DBMS functions. They are replaced at code
generation time by their implementation.

17 - 16 Copyright © 2007, Oracle. All rights reserved.


Why Use a Source Command?

• The command sent to the source should return a result


set, which is manipulated by the default command.
• Example: Transferring data from a table to another
– Source Command: SELECT statement
– Default Command: INSERT statement with source
columns in bind mode

17 - 17 Copyright © 2007, Oracle. All rights reserved.


3. Adding options

Using Options to Control the Procedure

17 - 18 Copyright © 2007, Oracle. All rights reserved.


Types of Options

• Options are typed procedure parameters.


– Checkbox, value, or text
• Options are used to control procedures:
– Commands may or may not be executed depending on
the values of checkbox options.
– Value or text options can be used within the command to
parameterize the code.
• Options have a default value. The value can also be
specified when the procedure is used.

17 - 19 Copyright © 2007, Oracle. All rights reserved.


How to Create a New Option

1. Right-click the name


of the procedure.
2. Select Insert Option.
3. Fill in the:
– Name
– Description
– Help
4. Select a:
– Type
– Default Value
– Position to
display in

17 - 20 Copyright © 2007, Oracle. All rights reserved.


How to Make a Command Optional

1. Open a command, then


select the Options tab.
2. Check the option box if it

should trigger the


command execution.
3. If the command should
run, independently of any
options, check Always
Execute option.

17 - 21 Copyright © 2007, Oracle. All rights reserved.


Using an Option Value in a Command

In the command code, add the following code:


<%=odiRef.getOption("option_name")%>
• This code is replaced by the value of the option at run
time.
– Use quotation marks as appropriate.
• The value of the option is specified when the procedure
is used within a package. Otherwise, the default value
is used.

17 - 22 Copyright © 2007, Oracle. All rights reserved.


4. Running a Procedure

Manual Execution, Packages

17 - 23 Copyright © 2007, Oracle. All rights reserved.


Procedure Execution

• A procedure can be executed


manually for testing.
– Default option values are used.
• It is usually run from a package.
– Add a procedure step by dragging and dropping.
– Option values can be overridden at that time.

17 - 24 Copyright © 2007, Oracle. All rights reserved.


Using Operator to View Results

• Procedure is executed
as a session with one
step.
• One task for each
command:
– Warning: error was
ignored
– Tasks completed
successfully
– Error that was
not ignored
– Task waiting
to be run

17 - 25 Copyright © 2007, Oracle. All rights reserved.


Note: Procedure Steps Are References

A procedure used in a package is referenced by the


package, not copied.
Changes to the original procedure also apply to the
package.

17 - 26 Copyright © 2007, Oracle. All rights reserved.


Summary

• Creating simple procedures


• Adding commands
• Providing options
• Running a procedure

17 - 27 Copyright © 2007, Oracle. All rights reserved.

You might also like