Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
TOAD
Exercises for Hands-on
All ideas and information contained in this document are the intellectual property of
Education and Research Department, Infosys Technologies Limited. This document is
not for general distribution and is meant for use only for the person they are
specifically issued to. This document shall not be loaned to anyone, within or outside
Infosys, including its customers. Copying or unauthorized distribution of this
document, in any form or means including electronic, mechanical, photocopying or
otherwise is illegal.
Background
This document contains the assignments to be completed as part of the hands on for the
subject ORACLE (Course code: ).
Assignment 1
Objective: To learn how to connect to TOAD
Background: Although on your machine TOAD is pre configured but please follow these steps
to get a feel of how actually this has been configured.
Step 1:
Step 2:
Getting connected to Oracle through TOAD supplying your Userid ,Password and
Hoststring
Step 3:
After getting connected to Oracle through TOAD the following screen would appear.
Summary: You have learnt how to get connected to Oracle using TOAD
Note:
ENRTOAD must be showing your Oracle ID.(eg: TJan07LC1Comp55)
Assignment 2
Objective: To learn how to create tables, apply constraints and generate ER Diagram using
TOAD
DEPT
Column name Data type Description
PROJECT
Column name Data type Description
Step 1:
Goto Database >>Create >>Table
You will get the following screen.
Step 2:
After adding all the columns to the EMP table the following screen would appear.
It shows all the 6 columns of the EMP table with their sizes as well.
Step 3:
To add constraints to the already existing columns click on the Constraints tab of the same
form.
Click on Add Constraint tab of the form.
The following screen will appear.
Step 4:
To add the Primary key constraint select the column on which you want to set the property of
primary key.
The selected table column will appear in the Constraint columns.
Note:
You should have selected only the required columns for the desired constraint.
Constraint name will be generated by the tool.
The primary key option would have been set to Yes.
Step 3:
To add check constraint to the Sal column click on the Constraints tab in the window and
choose Check constraint.
It will open a Constraint text window to write the logic of check constraint.
The check constraint counter will start reflecting the count 1.
Step 4:
To check all the applied constraints on the columns go to the database menu and choose
Schema Browser or the same icon will be available in the tool bar.
Step 5:
The following screen would appear.
The left frame shows the created tables list.
As EMP is the only table that is created so far, so only it will appear in the list.
Step 6:
After the creation of all the three tables the following screen would be seen with the left
frame having in list of all the 3 tables.
Notice the Table tab in the left frame is selected.
Step 7:
After the creation of a table the constraints on its columns can be checked by clicking on the
Constraints tab on the left frame.
Then select on any constraint name, the right frame will reflect its details.
Step 8:
To check for the ER diagram of the relational schema, click on the Database >> Report >> ER
Diagram.
Step 9:
Click on the new ER Diagram(the first icon which is shown tabbed).
Step 10:
Select your UserID in the schema and EMP/EMPLOYEE table name in the table list.
Let all the check boxes be ticked.
Click on ok.
Step 11:
The following ER Diagram must appear.
It shows the relationship of EMPLOYEE table with all the other tables in the database via
foreign keys.
Step 12:
Save the ERD of the schema by clicking on the save icon at the top of the frame.
It will ask for the name ,save it as bitmap file with the extension .bmp.
Assignment 3
Objective: To learn how to create sequence, view and trigger using TOAD
Step 1:
Go to Database>>Create>>Sequence option.
Step 2:
Supply the name of the sequence, the start value and the increment value.
Step 3:
To check for the existing Sequences got to Databse>>Schema Browser or you can click on its
icon in the tool bar.
Step 4:
Click on the Sequence tab in the left frame.
On the right frame it will reflect all the details of the selected sequence.
Step 1: Select View option from Database >> Create menu. You will see the following
window.
Step 2: When it is prompting for View Name, type the view name and type the following
query in the text window provided.
Step 3: Click on Validate Query, and then you will see Query parsed OK, if the query runs
without any errors.
Step 2: Provide the Trigger name, select the Schema name and Table name on which the
trigger is to be created.
Step 3: Also click on the Fire when, Fire on and For each options as given below
Step 4: Select the When Clause window and provide the condition for the when clause as
given below.
NEW.job = SALESMAN
Step 6: Finally you can see the trigger created from Schema browser.
Assignment 4
Objective: To learn how to create a Store Procedure, SP template and how to call a SP from
an anonymous block using TOAD.
Step 1:
Go to Database>>Schema Browser option.
The following window will appear.
Select the Treeview from the Browser Style.
Step 2:
Step 3:
To see the existing Stored Procedures expand the tab of Procedure.
Step 4:
Right click on the Procedure Tab and go for View/Edit package save option
Step 5:
Go for the first procedure tab file path
Step 6:
Click on edit file and the file opens
With the following code
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 %SYSDATE% %USERNAME% 1. Created this procedure.
NOTES:
******************************************************************************/
BEGIN
tmpVar := 0;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END %YourObjectName%;
Step 6:
Let the file remain open
Then click on add to add a new SP template
Step 8:
Path will be the same as old Procedure template path and name of file will be the name of
the new SP template.
Step 9:
Try editing the new file.
The following screen appears.
Click on yes to save the file, as it does not exist it will create a new file with this name and
save it.
Step 10:
Copy the contents of the old Procedure template in this new file with the following changes
highlighted in blue color
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 %SYSDATE% %USERNAME% 1. Created this procedure.
NOTES:
******************************************************************************/
BEGIN
tmpVar := 0;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END %YourObjectName%;
Step 11:
Step 12:
Now Come back to the schema browser and right click on the procedure tab to create a new
SP.
Step 13:
Fill in the following details and choose the new proc template as directed below.
Step 14:
Save it.
After this the following screen would appear.
Step 15:
After the Procedure is created, create an anonymous block for calling it.
declare
Result number;
begin
TryProc(&a,&b,Result);
dbms_output.put_line('The result is'||Result);
end;
Step 16:
Now execute this SP.
Set serveroutput on.
It will ask for 2 inputs at the run time
Supply the following data
Step 17:
After execution the following output will appear in the output window.
Assignment 5
Objective: To learn how to use Debug options of TOAD
Step 1:
In TOAD Select Database Schema Browser
Select Procedures from Schema Browser
Step 2:
Select the Procedure to be debugged.
Step 3:
As shown in the figure below, load the procedure in the Procedure editor.
Once it is loaded, you can see a new window for the procedure editor.
Step 4:
Before using any debug options, we need to set the values for input parameters of the
procedure selected. In Debug menu select Set Parameters options.
Step 5 :
Now you can see a new window opened and the parameters of the procedure are listed. One
by one we need to set the values for all IN and INOUT parameters. The following pictures
illustrate this method for two input parameters (pNum1 and pNum2).
Step 6:
Once the parameters are set with the values, the procedure is ready for debug operation.
Here we will see how to set a break point. Go to Debug menu in Procedure editor, and select
Set Breakpoint option after placing the cursor in the appropriate line. Debug Set
Breakpoint.
Once the Breakpoint is set, it will be highlighted with a red line, as shown below.
Step 7:
We can add watches too. Go to Debug menu and select Watches option.
The Watch window will be opened as shown below. Here, select the add watch option
available in the watch window. (See the below snap shot)
Once you click on Add watch option, a window will be popped and it will prompt for
expression to be watched. Type an expression, or variable to be watched. The following snap
shots illustrate, to add watches for variables pNum1 and pNum2.
Please find below, the snap shot to display the added watch variables in the watch window.
(It shows process not accessible because we have not yet started the debug/ trace operation)
Step 8:
Now we can start tracing the execution of the procedure. Go to Debug menu and select Trace
Into option. Debug Trace Into.
It will prompt with the following message Do you want to compile referenced objects with
Debug information? This process can take several seconds. Click on Yes.
The Tracing is started and it will show the tracing line with highlighted color.
Every time press shift+F7 or select the Trace Into option from Debug menu.
While tracing the procedure execution, we can watch the variables added for watch option in
the watch window.
Assignment 6
Objective: To learn how to use the DBMS output window of SQL Editor.
The following demo is to show the use of DBMS Output window available in SQL Editor of
TOAD.
Step 1:
Type the following code in SQL Editor, as given in the snap shot. Click on DBMS Output
window, and click on the clear window button.
Step 2:
Click on the Turn Output On button as shown in the below snap shot.
Step 3:
Go to Debug menu and select the Run option.
Once you Run the script, the DBMS Output window will show the output.
Assignment 7
Objective: To learn how to use the CodeXpert option of SQL Editor.
Step 1:
Type the following query in SQL Editor.
Step2 :
Now we can see the suggestions given by CodeXpert in the bottom window.