Getting Started with Oracle SQL Developer 4.0 (2023)

Overview

Purpose

This tutorial introduces Oracle SQL Developer 4.0 and shows you how to manage your database objects.

Time to Complete

Approximately 50 minutes

Introduction

Oracle SQL Developer is a free graphical tool that enhances productivity and simplifies database development tasks. Using SQL Developer, you 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 OS X. This is a great advantage to the increasing number 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.

Prerequisites

Before starting this tutorial, you should:

  • Install Oracle SQL Developer 4.0 from OTN. Follow the readme instructions here .
  • Install Oracle Database 12c with the Sample schema
  • Unlock the HR user. Login to SQL Developer as the SYS user and execute the following command:
    alter user hr identified by hr account unlock;
  • Download and unzip the files.zip to a local folder on your file system. In this tutorial, we use the C:\sqldev3.0 folder.
  • Note: This tutorial was created in a Linux environment. If you are using a Windows environment, the screenshots may be slightly different.

Creating a Database Connection

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

  1. If you installed the SQL Developer icon on your desktop, click the icon to start your SQL Developer and move to Step 4. If you do not have the icon located on your desktop, perform the following steps to create a shortcut to launch SQL Developer 4.0 directly from your desktop.

    In Windows, open the directory where the SQL Developer 4.0 is located, right-click sqldeveloper.exe and select Send to > Desktop (create shortcut).

    Getting Started with Oracle SQL Developer 4.0 (1)

    In Linux, right-click in your Desktop and select Create Launcher and enter the application details.

    Getting Started with Oracle SQL Developer 4.0 (2)
  2. On the desktop, you will find an icon named Shortcut to sqldeveloper.exe (in Windows) or SQL Developer4.0 (in Linux). Double-click the icon to open SQL Developer 4.0.

    Getting Started with Oracle SQL Developer 4.0 (3)
  3. Your Oracle SQL Developer opens.

    Getting Started with Oracle SQL Developer 4.0 (4)
  4. In the Connections navigator, right-click Connections and select New Connection.

    Getting Started with Oracle SQL Developer 4.0 (5)
  5. The New / Select Database Connection dialog opens. Enter the connection details as follows and click Test.

    Connection Name: HR_ORCL
    User Name: hr
    Password: <your_password> (Select the Save Password checkbox)
    Connection Color: Select the red color. (The color is set as the border of any SQL Worksheet and other windows associated with the connection. Setting the color connection is useful when working with multiple connections.)
    Hostname: localhost
    SID: <your_own_SID>
    Getting Started with Oracle SQL Developer 4.0 (6)

    Note: In this tutorial the Service Name is specified instead of SID.

  6. Check for the status of the connection on the left-bottom side (above the Help button). It should read Success. Click Connect. Then click Save.

    Getting Started with Oracle SQL Developer 4.0 (7)
  7. The connection was saved and you see the newly created connection in the Connections list.

    Getting Started with Oracle SQL Developer 4.0 (8)
  8. Expand HR_ORCL.

    Getting Started with Oracle SQL Developer 4.0 (9)

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

  9. Expand Tables.

    Getting Started with Oracle SQL Developer 4.0 (10)
  10. Select the EMPLOYEES table to view the table definition. Then click the Data tab.

    Getting Started with Oracle SQL Developer 4.0 (11)
  11. The data in the table is shown. In the next topic, you create a new table and populate the table with data.

    Getting Started with Oracle SQL Developer 4.0 (12)
  12. You can sort the EMPLOYEES table data by double clicking the arrow icon next to the column you want to sort on. Here the table data is sorted on EMP_ID.

    Getting Started with Oracle SQL Developer 4.0 (13)
  13. To filter the table data, click on the filter icon next to the column you want to set the filter on. Here the filter is set in the SALARY column.

    Getting Started with Oracle SQL Developer 4.0 (14)

    Getting Started with Oracle SQL Developer 4.0 (15)

  14. To remove the filter, click Remove.

    Getting Started with Oracle SQL Developer 4.0 (16)
  15. Click the DEPARTMENTS table in the Connections navigator.

    Getting Started with Oracle SQL Developer 4.0 (17)
  16. There are a number of constraints for the DEPARTMENTS table. To view the various constraints on the table, click the Constraints tab.

    Getting Started with Oracle SQL Developer 4.0 (18)
  17. Note that the DEPARTMENTS table has 4 constraints. Each constraint has a unique name. The CONSTRAINT_TYPE identifies the type of constraint on the table.

    Click Edit Getting Started with Oracle SQL Developer 4.0 (19).

    Getting Started with Oracle SQL Developer 4.0 (20)
  18. The Edit Table dialog has a number of fields. Select Constraints beneath the Search field.

    Getting Started with Oracle SQL Developer 4.0 (21)
  19. Review the Foreign Keys constraints. Note that the DEPARTMENTS table has two foreign keys, one named DEPT_LOC_FK and the other named DEPT_MGR_FK.
    When you select one of the names in the Foreign Keys field, the details about that foreign key appear.

    Click OK to leave the Edit Table dialog.

    Getting Started with Oracle SQL Developer 4.0 (22)

Adding a New Table Using the Create Table Dialog Box

In this section, you create a new table called DEPENDENTS. You create columns in the DEPENDENTS table. Your table will have the columns ID, FIRST_NAME, LAST_NAME, BIRTHDATE, and RELATION.
Later, you create a foreign key on the DEPENDENTS table to associate the column's values with the EMPLOYEES. Perform the following steps:

  1. Right-click Tables and select New TABLE...

    Getting Started with Oracle SQL Developer 4.0 (23)
  2. Enter DEPENDENTS for the Table Name and select the Advanced check box.

    Getting Started with Oracle SQL Developer 4.0 (24)
  3. For the first column in your table, enter ID for the Name, select NUMBER for the Datatype and enter 6 for the Precision (length of the number). Select Cannot be NULL, then click Add Column Getting Started with Oracle SQL Developer 4.0 (25) .

    Note: By checking Cannot be NULL, you are adding a constraint on the table that specifies the column must hold values.

    Getting Started with Oracle SQL Developer 4.0 (26)
  4. For the next column, enter FIRST_NAME for the Name, leave the type as VARCHAR2 and enter 20 for the Size to specify the length of the VARCHAR2. Then click Add Column Getting Started with Oracle SQL Developer 4.0 (27) .

    Getting Started with Oracle SQL Developer 4.0 (28)
  5. For the next column, enter LAST_NAME for the Name, leave the type as VARCHAR2 and enter 25 for the Size. Select the Cannot be NULL check box. Then click Add Column Getting Started with Oracle SQL Developer 4.0 (29) .

    Getting Started with Oracle SQL Developer 4.0 (30)
  6. For the next column, enter BIRTHDATE for the Name, select DATE for the type. Then click Add Column Getting Started with Oracle SQL Developer 4.0 (31) .

    Getting Started with Oracle SQL Developer 4.0 (32)
  7. For the last column, enter RELATION for the Name, leave type as VARCHAR2 and enter 25 for the Size. Click OK to create the table.

    Getting Started with Oracle SQL Developer 4.0 (33)
  8. Your new table appears in the list of tables.

    Getting Started with Oracle SQL Developer 4.0 (34)

Changing a Table Definition

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

  1. In the Connections navigator, select the DEPENDENTS table.

    Getting Started with Oracle SQL Developer 4.0 (35)
  2. Right-click, select Column then Add...

    Getting Started with Oracle SQL Developer 4.0 (36)
  3. Enter RELATIVE_ID, select NUMBER for the Data Type (from the drop list), set the Precision to 6 and Scale to 0.

    Getting Started with Oracle SQL Developer 4.0 (37)
  4. The confirmation verifies that a column has been added.

    Click OK.

    Getting Started with Oracle SQL Developer 4.0 (38)
  5. Expand the DEPENDENTS table to review the updates.

    Getting Started with Oracle SQL Developer 4.0 (39)

Adding Table Constraints

In this topic, you create the Primary and Foreign Key Constraints for the table. Constraints are a way of validating data. A Primary Key constraint ensures that a column's values are unique and present (not null).
A Foreign Key constraints maintains data integrity between two different columns (one of which may be in a separate table). Perform the following steps:

  1. Right-click DEPENDENTS table and select Edit...

    Getting Started with Oracle SQL Developer 4.0 (40)
  2. Click the Constraints node in the tree.

    Getting Started with Oracle SQL Developer 4.0 (41)
  3. Click the drop down arrow next to the Add Constraint icon Getting Started with Oracle SQL Developer 4.0 (42) and select New Primary Key Constraint.

    Getting Started with Oracle SQL Developer 4.0 (43)
  4. Select the ID column and click Getting Started with Oracle SQL Developer 4.0 (44) to shuttle the value to the Selected Columns window.

    Getting Started with Oracle SQL Developer 4.0 (45)

    This identifies that the ID column in the DEPENDENTS table has a Primary Key constraint. All of the values in this column must be unique and must be present.

  5. Next, you add a Foreign Key constraint. Click the drop down arrow next to the Add Constraint icon Getting Started with Oracle SQL Developer 4.0 (46) and select New Foreign Key Constraint

    Getting Started with Oracle SQL Developer 4.0 (47)
  6. You will link the RELATIVE_ID column in the DEPENDENTS table to the ID column in the EMPLOYEES table. This will ensure that any value added in the the RELATIVE_ID column must match an existing value in the ID column of the EMPLOYEES table.
    Under the Referenced Constraint section, ensure the schema selected is HR. Select EMPLOYEES from Table drop list. Ensure that the Constraint field holds the value EMP_EMP_ID_PK.
    In the Associations field, select RELATIVE_ID for the Local Column field and click OK.

    Getting Started with Oracle SQL Developer 4.0 (48)

Adding Data to a Table

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

  1. With the DEPENDENTS table still selected, you should have the Data tab already selected. If not, select it.

    Getting Started with Oracle SQL Developer 4.0 (49)
  2. Then click Insert Row Getting Started with Oracle SQL Developer 4.0 (50).

    Getting Started with Oracle SQL Developer 4.0 (51)
  3. Enter the following data and then click Commit Getting Started with Oracle SQL Developer 4.0 (52) to save the row to the database.

    ID: 209
    FIRST_NAME: Sue
    LAST_NAME: Littlefield
    BIRTHDATE: 01-JAN-97
    RELATION: Daughter
    RELATIVE_ID: 110
    Getting Started with Oracle SQL Developer 4.0 (53)
  4. The outcome of the commit action displays in the log window. The SQL statement that was committed is listed beneath the Commit Successful message.

    Getting Started with Oracle SQL Developer 4.0 (54)
  5. You can also load multiple rows at one time using a script. Click File > Open...

    Getting Started with Oracle SQL Developer 4.0 (55)
  6. Navigate to the sqldev3.0 directory, select the load_dep.sql file and click Open.

    Getting Started with Oracle SQL Developer 4.0 (56)
  7. Select the HR_ORCL connection in the connection drop list to the right of the SQL Worksheet.

    Getting Started with Oracle SQL Developer 4.0 (57)
  8. The SQL from the script is shown. Click Run Script Getting Started with Oracle SQL Developer 4.0 (58).

    Getting Started with Oracle SQL Developer 4.0 (59)

    The data is inserted. Click the DEPENDENTS tab to view the results.

    Getting Started with Oracle SQL Developer 4.0 (60)
  9. To view the data, make sure the Data tab is selected and click Refresh Getting Started with Oracle SQL Developer 4.0 (61) to show all the data.

    Getting Started with Oracle SQL Developer 4.0 (62)

    All of the data is displayed

    Getting Started with Oracle SQL Developer 4.0 (63)
  10. You can export the data so it can be used in another tool, such as, a spreadsheet. Right-click on one of the values in any column and select Export.

    Getting Started with Oracle SQL Developer 4.0 (64)
  11. Click on the drop down next to Format and select the format you want to export the data into, such as csv. Note that you have various format options available.

    Click Next.

    Getting Started with Oracle SQL Developer 4.0 (65)
  12. The Export Summary is displayed. Click Finish.

    Getting Started with Oracle SQL Developer 4.0 (66)
  13. If you review the export.csv file, you should see the following:

    Getting Started with Oracle SQL Developer 4.0 (67)

Accessing Data

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

  1. Select the HR_ORCL Database Connection, right-click and select Open SQL Worksheet

    Getting Started with Oracle SQL Developer 4.0 (68)
  2. Drag and Drop the DEPENDENTS table from the list of database objects in the Connections navigator to the SQL statement worksheet area.

    Getting Started with Oracle SQL Developer 4.0 (69)
  3. A dialog window appears. You can specify the type of SQL statement to create. Accept the default to create a SELECT statement and click Apply.

    Getting Started with Oracle SQL Developer 4.0 (70)
  4. Your SELECT statement is displayed. You can modify it in the SQL Worksheet and run it.

    Getting Started with Oracle SQL Developer 4.0 (71)
  5. Add the WHERE clause where relative_id > 110 to the end of the SELECT statement BEFORE the ';'.

    Click Run Statement Getting Started with Oracle SQL Developer 4.0 (72) .

    Getting Started with Oracle SQL Developer 4.0 (73)
  6. The results are shown. Only rows where the RELATIVE_ID > 110 are displayed.

    Getting Started with Oracle SQL Developer 4.0 (74)

Creating Reports

If you need to execute a SQL statement 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.
Bind variables enable you to run your query multiple times and pass in different values. Perform the following steps:

  1. Highlight the SQL statement in the HR_ORCL SQL Worksheet that you executed, right-click and select Create Report...

    Getting Started with Oracle SQL Developer 4.0 (75)
  2. Enter the name RELATIVE_ID greater than 110 into the Name field. Optionally, you can add a Description and a Tooltip. Click Apply.

    Getting Started with Oracle SQL Developer 4.0 (76)
  3. Select the Reports tab, expand User Defined Reports. You should see the report you created in the previous step. Select the report you just created.

    Getting Started with Oracle SQL Developer 4.0 (77)
  4. In the Select Connection dialog, select HR_ORCL from the drop list and click OK to connect to your database and run the report.

    Getting Started with Oracle SQL Developer 4.0 (78)
  5. The results of your report are shown.

    Getting Started with Oracle SQL Developer 4.0 (79)
  6. You can also run a Data Dictionary report. Data dictionary reports hold meta data about your objects. This includes information such as your table definitions.

    Expand Data Dictionary Reports > Data Dictionary. Then select Dictionary Views.

    Getting Started with Oracle SQL Developer 4.0 (80)
  7. Deselect the NULL check box, enter col for the Value and click Apply.

    Getting Started with Oracle SQL Developer 4.0 (81)
  8. All the Data Dictionary views that contain 'col' in its name are displayed.

    Getting Started with Oracle SQL Developer 4.0 (82)

Creating and Executing PL/SQL

Oracle SQL Developer contains extensive PL/SQL editing capabilities. In this topic, you create a Package Specification and Package Body. This package adjusts an employee's salary.
Perform the following steps:

  1. Select File > Open using the main menu.

    Getting Started with Oracle SQL Developer 4.0 (83)
  2. Browse to the sqldev3.0 directory, select createHRpack.sql. Click Open.

    Getting Started with Oracle SQL Developer 4.0 (84)
  3. Select the HR_ORCL database connection from the the drop list on the right.

    Getting Started with Oracle SQL Developer 4.0 (85)
  4. Click Run Script Getting Started with Oracle SQL Developer 4.0 (86) .

    Getting Started with Oracle SQL Developer 4.0 (87)
  5. The package specification and the package body compile successfully.

    Note: The script first drops the package, so the first time you run this script, you will see ora errors. Ignore the errors and observe the output at the bottom that the package is created.

    Click the Connections navigator.

    Getting Started with Oracle SQL Developer 4.0 (88)
  6. Expand HR_ORCL > Packages and select HR_PACK to verify and view the package definition.

    Getting Started with Oracle SQL Developer 4.0 (89)
  7. Double-click HR_PACK BODY to view the package body definition.

    Getting Started with Oracle SQL Developer 4.0 (90)
  8. Click any one of the - to collapse the code or press + to expand the code.

    Getting Started with Oracle SQL Developer 4.0 (91)
  9. 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.

    Getting Started with Oracle SQL Developer 4.0 (92)
  10. You can split the code editor display either horizontally or vertically. To do so, right click HR_PACK Body and select Split Vertically for a vertical split or Split Horizontally for a horizontal split.

    Getting Started with Oracle SQL Developer 4.0 (93)
  11. Select Unsplit to go back to the original view.

    Getting Started with Oracle SQL Developer 4.0 (94)
  12. In the Connections Navigator, select Packages > HR_PACK, right-click and select Run.

    Getting Started with Oracle SQL Developer 4.0 (95)
  13. A parameter window appears. Make sure that the GET_SAL target is selected. You need to set the input parameters here for P_ID and P_INCREMENT. Input parameters are values that you are passing into the program at runtime.

    Getting Started with Oracle SQL Developer 4.0 (96)
  14. Set the P_ID to 102 and P_INCREMENT to 1.2. This means for 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.

    Getting Started with Oracle SQL Developer 4.0 (97)
  15. The value returned is 20400.

    Getting Started with Oracle SQL Developer 4.0 (98)
  16. To test the Exception Handling, right-click on HR_PACK in the navigator and select Run.

    Getting Started with Oracle SQL Developer 4.0 (99)
  17. This time, change the P_INCREMENT value to 5 and click OK.

    Getting Started with Oracle SQL Developer 4.0 (100)
  18. In this case, an exception was raised with "Invalid increment amount" because the P_INCREMENT value was greater than 1.5.

    Getting Started with Oracle SQL Developer 4.0 (101)

Summary

In this tutorial, you learned to:

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

Resources

  • To learn more about SQL Developer 4.0 refer to additional OBEs in the Oracle Learning Library

Credits

  • Lead Curriculum Developer: Swarnapriya Shridhar
  • Other Contributors: Ashley Chen

FAQs

How do I start working with Oracle SQL Developer? ›

To start SQL Developer: From the Start menu, select All Programs, then Oracle - HOMENAME, then Application Development, and then SQL Developer. If you are prompted to enter the full path name for java.exe, click Browse and find java.exe . For example, C:\Program Files\Java\jdk1.

Is Oracle SQL easy or hard? ›

It's relatively easy to learn — as long as you have a good handle on Linux and SQL. If you have already learned SQL Server, then you can certainly learn Oracle databases. Oracle isn't necessarily harder to learn than Microsoft SQL Server — it's just different.

How can I practice Oracle SQL at home? ›

  1. 7 Best Platforms to Practice SQL. Looking to level up your SQL skills? ...
  2. HackerRank. From software engineering to data analytics, HackerRank is one of the best platforms for practicing coding interview questions. ...
  3. SQLPad. ...
  4. StrataScratch. ...
  5. DataLemur. ...
  6. LeetCode. ...
  7. Mode. ...
  8. SQLZoo.
Jan 13, 2023

How long does it take to learn Oracle Database? ›

If you already have a career in computer system programming or you are competent around, learning the Oracle database takes just 2 to 3 weeks. Oracle database training offers you the core expertise you need to come to be a successful Oracle DBA.

Top Articles
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated: 12/10/2023

Views: 6362

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.