Managing Your Database Objects Using Oracle SQL Developer

This tutorial describes how to use Oracle SQL Developer to manage your database objects.

Approximately 30 minutes

This tutorial covers the following topics:

bullet
bullet
bullet
bullet
bullet
bullet
bullet
bullet
bullet
bullet
bullet

Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.

Oracle SQL Developer is a new, free graphical tool that enhances productivity and simplifies database development tasks. Using SQL Developer, users can browse database objects, run SQL statements, edit and debug PL/SQL statements and run reports, whether provided or created.

Developed in Java, SQL Developer runs on Windows, Linux and the Mac. This is a great advantage to the increasing numbers of developers using alternative platforms. Multiple platform support also means that users can install SQL Developer on the Database Server and connect remotely from their desktops, thus avoiding client server network traffic. Default connectivity to the database is through the JDBC Thin driver, so no Oracle Home is required. To install SQL Developer simply unzip the downloaded file. With SQL Developer users can connect to Oracle Databases 9.2.0.1 and later, and all Oracle database editions including Express Edition.

Before you perform this tutorial, you should:

1.

Install Oracle Database 11g

2. Download and unzip sqldev.zip into your working directory (i.e. d:\wkdir)
3.

Make sure the DEPENDENTS table doesn't exist. Open SQL*Plus and execute the following commands:

connect hr/hr
drop table dependents;

Back to Topic List

The first step to managing database objects using Oracle SQL Developer is to create a database connection. Perform the following steps:

1.

Open a terminal window and execute the following commands:

cd $ORACLE_HOME/sqldeveloper/sqldeveloper/bin
./sqldeveloper

 

2.

In the Connections tab, right-click Connections and select New Connection.

 

3.

Enter <your_db_sid_name>_HR for the Connection Name (or any other name that identifies your connection), hr for the Username and Password, specify your <hostname> for the Hostname and enter <your_db_sid> for the SID. Then click Test.

 

4.

The status of the connection was tested successfully. The connection was not saved however. To save the connection, click Connect.

 

5.

The connection was saved and you see the database in the list. Expand ORCL_HR.

Note: When a connection is opened, a SQL Worksheet is opened automatically. The SQL Worksheet allows you to execute SQL against the connection you just created.

 

6.

Expand Tables.

 

7.

Select the Table EMPLOYEES to view the table definition.

 

8.

To see the data, click the Data tab.

 

9.

The data is shown. In the next topic, you create a new table and populate the table with data.

 

You create a new table called DEPENDENTS which has a foreign key with the EMPLOYEES table. Perform the following steps:

1.

Right-click Tables and select New Table.

 

2.

Enter DEPENDENTS for the Table Name and click the Advanced check box.

 

3.

Enter ID for the Name, select NUMBER for the Data type and enter 6 for the Precision. Select the Cannot be NULL check box. Then click the Add Column icon.

 

4.

Enter FIRST_NAME for the Name, and enter 20 for the Size. Then click the Add Column icon.

 

5.

Enter LAST_NAME for the Name, enter 25 for the Size. Select the Cannot be NULL check box. Then click the Add Column icon.

 

6.

Enter BIRTHDATE for the Name, select DATE for the Data type. Then click the Add Column icon.

 

7.

Enter RELATION for the Name, and enter 25 for the Size. Then click the Add Column icon.

 

8.

Enter GENDER for the Name, and enter 1 for the Size. Then click the Add Column icon.

 

9.

Enter RELATIVE_ID for the Name, select NUMBER for the Data type, and enter 6 for the Precision. Select the Cannot be NULL check box. Then click OK to create the table.

 

10.

Your new table appears in the list of tables. Select DEPENDENTS from the list.

 

Back to Topic List

Oracle SQL Developer makes it very easy to make changes to database objects. In this topic, you delete a column in the DEPENDENTS table you just created. Perform the following steps:

1.

Click the Actions... button.

 

2.

Select Column then Drop.

 

3.

Select the Column Name GENDER and click Apply.

 

4.

The column has been dropped. Click OK.

 

5.

Select the Refresh icon to refresh the list of columns for the table.

 

6.

The Gender column is no longer in the list.

 

Back to Topic List

In this topic, you create the Primary and Foreign Key Constraints for the DEPENDENTS table. Perform the following steps:

1.

Right-click DEPENDENTS table and select Edit.

 

2.

Select Primary Key from the list.

 

3.

Select the ID column and click > the select Foreign Key from the list.

 

4.

Click Add.

 

5.

Select EMPLOYEES for the Referenced Table and select RELATIVE_ID for the Local Column and click OK.

 

Back to Topic List

You can add data to a table by performing the following steps:

1.

Click the Insert Row icon.

 

2.

Enter the following data and click the Commit Changes icon.

ID
FIRST_NAME
LAST_NAME Littlefield
BIRTHDATE 01-JAN-97
RELATION Daughter
RELATIVE_ID 110

 

3.

The row you just added was committed to the database.

 

4.

You can also load multiple rows at one time using a script. Click the SQL Worksheet ORCL_HR tab.

 

5.

Right-click in the SQL Statement area and select Open File.

 

6.

Navigate to your working directory (i.e. c:\wkdir) and select the load_dep.sql file and click Open.

 

7.

The SQL from the script is shown. Click the Run Script icon.

 

8.

The data was inserted. To view the data, click the DEPENDENTS tab.

 

9.

Click Refresh to show all the data.

 

10.

All the data in the table are listed.

 

11.

You can export the data so it can be used in another tool, for example, Excel. Right-click on one of the values in any column, select Export and then one of the file types.

 

12.

Specify the directory and name of the file and click Apply.

 

13.

If you review the DEPENDENTS.CSV file, you see the following.

 

Back to Topic List

One way to access DEPENDENTS data is to generate a SELECT statement on the DEPENDENTS table and add a WHERE clause. Perform the following steps:

1.

Click the SQL Worksheet tab.

 

2.

Click the clear (pencil) icon to remove the contents of the SQL Statement window.

 

3.

Drag and Drop the DEPENDENTS table from the list of database objects to the SQL statement area.

 

4.

A SELECT statement is shown with all the columns contained in the DEPENDENTS table. Scroll right to the end of the SELECT statement.

 

5.

Add the WHERE clause where relative_id > 110 to the end of the SELECT statement BEFORE the ';'. Then click the Execute Statement icon.

 

6.

The Results are shown.

 

Back to Topic List

Since the SQL you just ran in the previous topic needs to be executed frequently, you can create a custom report based on the SQL. In addition, you can run a report of your database data dictionary using bind variables. Perform the following steps:

1.

Select the SQL in the SQL Worksheet you just executed. Then click the Edit pulldown and select Copy.

 

2.

Click the Reports tab.

 

3.

Right-click User Defined Reports and select Add Folder.

 

4.

Enter the Folder Name DEPENDENTS RPTS and click Apply.

 

5.

Right-click DEPENDENT RPTS and select Add Report.

 

6.

Enter a Name for the report and click ctrl+v in the SQL area to paste the SQL you copied from the SQL Worksheet. Then click Apply.

 

7.

Expand DEPENDENTS RPTS.

 

8.

Select the Report you just created.

 

9.

Click OK to connect to your database.

 

10.

The results of your report are shown.

 

11.

You can also run a Data Dictionary report. Expand Data Dictionary Reports > Data Dictionary. Then select Dictionary Views.

 

12.

Deselect the NULL check box.

 

13.

Enter col for the Value and click Apply.

 

14.

All the Data Dictionary views that contain 'col' in its name are displayed.

 

Back to Topic List

Oracle SQL Developer contains extensive PL/SQL debugging capabilities. In this topic, you create a Package Spec and Package Body that adjusts an employees salary. Perform the following steps:

1.

Click the SQL Worksheet tab.

 

2.

Right-click in the SQL statement area and select Open File.

 

3.

From your working directory (c.\wkdir) select createHRpack.sql and click Open.

 

4.

Click the Run Script icon.

 

5.

Click the Connections tab on the left.

 

6.

The script ran successfully and the package and package body were created. Expand Packages.

 

7.

Select HR_PACK to view the package definition.

 

8.

Select HR_PACK BODY to view the package body definition.

 

9.

To make any changes to the Package Body, click the Edit icon.

 

10.

Click on any one of the + to collapse the code or press - to expand the code.

 

11.

If your line numbers do not appear, you can right-click in the line number area and click Toggle Line Numbers to turn them on. This is useful for debugging purposes.

 

12.

Right-click HR_PACK and select Run.

 

13.

A parameter window appears. You need to set the input parameters here.

Set the P_ID to 102 and P_INCREMENT to 1.2. What this means is that the Employee who has the ID 102, their salary is increased by 20%. The current SALARY for EMPLOYEE_ID 102 is 17000. Click OK.

 

14.

The value returned is 20400.

 

15.

To test the Exception Handling, right-click on HR_PACK in the navigator and select Run.

 

16.

This time, change the P_INCREMENT value to 5 and click OK.

 

17.

In this case, an exception was raised with "Invalid increment value" because the P_INCREMENT value was greater than 1.5.

 

Back to Topic List

In this tutorial, you learned how to:

bullet Create a database connection
bullet Add a new table using the Table Dialog Box
bullet Change a table definition
bullet Add data to a table
bullet Access data
bullet Generate a report
bullet Debug and execute PL/SQL

Back to Topic List

Move your mouse over this icon to hide all screenshots.