Oracle SQL Developer - Sample Chapter
Oracle SQL Developer - Sample Chapter
ee
$ 54.99 US
34.99 UK
P U B L I S H I N G
pl
e
P r o f e s s i o n a l
Sa
E x p e r t i s e
D i s t i l l e d
P U B L I S H I N G
Bangalore, India, and has more than 11 years of work experience as an Oracle
[apps] DBA and platform architect with expertise in infrastructure architecture,
capacity planning, and performance tuning of medium to large e-business suite
environments.
He holds a postgraduate degree with PGDBA (finance) from Symbiosis, Pune,
an M.S. (software systems) from BITS Pilani, a BE (electronics and communication)
from Amrita Institute of Technology, and a diploma (computer technology) from
Sree Narayana Guru Institute of Technology.
He has worked in different technical positions as an Oracle DBA, APPS DBA,
Oracle apps platform architect, and configuration management technical leader in
companies such as GE, Dell, JP MorganChase, Oracle, and TCS. Ajith was at GE
before joining InfraStack-Labs.
He is also a regular speaker at national and international Oracle user group
conferences such as SANGAM, NZOUG, DOAG, UKOUG, OTN APAC Tour,
AIOUG Tech Days, and so on. His white papers have been published on the Oracle
Technology Network in English, Portuguese, and Spanish. Ajith is currently serving
the ORACLERACSIG board as the web seminar chair (from October 2015), and has
previously served the board as the website chair (September 2011 to September 2013).
Preface
The book dives into the details of Oracle SQL Developer 4.1, which is a graphical
version of SQL*Plus. Oracle SQL Developer has been continuously evolving and
reaching maturity with the capability to give database developers and DBAs a
convenient way to perform basic and advanced database tasks. Oracle Developers
and DBAs can browse, create, edit, and delete (drop); run SQL statements and scripts;
edit and debug PL/SQL code; manipulate and export (unload) data; and view and
create custom reports.
After reading this book, Oracle developers and DBAs will learn to install Oracle SQL
Developer and learn to navigate through all its advanced features that have been
introduced in version 4.1. You will be competent enough to use all the advanced
features available, helping them perform basic and advanced database tasks with ease.
Preface
Chapter 4, Working with PL/SQL, shows you how to create, edit, compile, and debug
PL/SQL blocks efficiently in the first section, followed
by the use of SQL and PL/SQL tuning tools provided by SQL Developer.
Chapter 5, SQL Developer for DBAs, shows you how a DBA can leverage SQL
Developer's features to efficiently work with multiple databases in the areas
of manageability, monitoring, performance tuning, and so on.
Chapter 6, SQL Developer Accessibility, provides information about the accessibility
features of Oracle SQL Developer. It includes using a screen reader and Java access
bridge with Oracle SQL Developer, Oracle SQL Developer features that support
accessibility, recommendations for customizing Oracle SQL Developer, and highly
visual features of Oracle SQL Developer.
Chapter 7, Importing, Exporting, and Working with Data, uses SQL Developer features
such as the export/import feature using which we can easily and quickly export and
import data from within a database or across a database, and also compare all the
data after the activity.
Chapter 8, Database Connections and JDBC Drivers, uses alternative Oracle connections
such as tnsnames.ora, LDAP, JDBC URLs, and also shows you how to create
non-Oracle database connections.
Chapter 9, Introducing SQL Developer Data Modeler, uses data modeler features such
as diagrams, components, entity relationship diagrams, relational and physical data
models, and some forward/reverse engineering possibilities using SQL developer.
Chapter 10, Extending SQL Developer, helps you learn the range of support available
for adding XML extensions, a task that is easily within the reach of any database
developer with SQL and PL/SQL skills. The nature of these extensions can range
from including a single XML report to adding complex Java extensions bundled
as JAR files.
Chapter 11, Working with Application Express, shows you how to connect to
Application Express, browse your applications, review some of the administration
utilities, and use the SQL Worksheet to refactor PL/SQL code.
Chapter 12, Working with SQL Developer Migrations, reviews the tool support for a
migration without discussing the additional work required when planning and
preparing for a migration.
Preface
Chapter 13, Oracle Data Miner 4.1, teaches you about the new Data Miner features
in SQL Developer 4.1 and the general enhancements to Oracle Data Miner 4.1.
In response to the growing popularity of JSON data and its use in big data
configurations, Data Miner now provides an easy-to-use JSON query node.
Chapter 14, REST Data Services and REST Development, shows you how Oracle REST
Data Services (a JEE-based alternative to Oracle HTTP Server (OHS) and mod_plsql)
can be administered. The second session will be a detailed discussion of how we can
use SQL Developer to create, maintain, and use RESTful services.
[1]
Use this link to visit the page that will allow you to download the latest standalone
production release. It also includes details of the release and is regularly updated
with news of preview releases and new articles. While SQL Developer is free to
download and use, you are required to read and agree to the license before you can
proceed with the download. The product also falls under Oracle Support contracts;
if you have a Support contract for the database, then you can log in to Oracle
Support tickets.
[2]
Chapter 1
In each case, make your selection and download the required file.
JDK 8 can be downloaded using the following link:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8downloads-2133151.html
SQL Developer is shipped with the minimum JDK required for each
release. You can download and use the latest updates to the JDK and
should be aware that some updates to the JDK are not supported. This
detail is posted on the SQL Developer Downloads page for each release.
Starting from SQL Developer 4.1, JDK 1.8 is the minimum JDK supported.
Once you have installed the JDK, you can start SQL Developer.
[3]
Microsoft Windows
The first executable you'll find is in the \sqldeveloper root folder. This is the
executable more generally used. If you navigate down to \sqldeveloper\bin, there
are two additional executables, sqldeveloper.exe and sqldeveloperW.exe. The
latter is the same as the executable in the root folder. Use either of these for running
SQL Developer.
The additional executable is often used for debugging purposes. Use \
sqldeveloper\bin\sqldeveloper.exe to invoke SQL Developer and a separate
console window will open, which displays additional Java messages. You can use
these messages when encountering errors in the product and if you want to log an
issue with Oracle Support.
The three steps to getting started on Microsoft Windows are as follows:
Download: Download the full file, with JDK, from the Oracle Technology
Network web site
Alternative platforms
Microsoft Windows is the predominant platform used by SQL Developer users.
There is a steadily growing audience for Linux and Max OS X. As neither of these
platform downloads include the JDK, you need to first access, download, and install
the JDK. On starting either Linux or the Mac OS, you'll be prompted with the full
path of the JDK as described.
Mac OS X
Download the file specific to Mac OS X and double-click to unzip the file. This creates
an icon for SQL Developer on your desktop. Double-click to run the application.
Linux
Use the Linux rpm command to install SQL Developer. For example, your command
might look like the following:
rpm -Uhv sqldeveloper-4.1.0.19.07-1.noarch.rpm
[4]
Chapter 1
In the same way that unzip creates a sqldeveloper folder, with sub-folders and
files, the rpm command creates a sqldeveloper folder, complete with files and
sub-folders. Switch to this new folder and run the sqldeveloper.sh executable.
If you want to migrate from a different installation, select the Show All Installations
button (as shown in the preceding screenshot). This displays a list of all SQL
Developer installations that have the system folder in the Documents and Settings
system folder (e.g. C:\Documents and Settings\<your_user>\Application
Data\SQL Developer\system4.1.0.19.07-1) and includes releases from SQL
Developer 1.5 and above. For releases prior to SQL Developer 1.5, the system folder
was created within the SQL Developer installation (for example, D:\SQLDeveloper\
Builds\1.2.1\1.2.1.3213\sqldeveloper\sqldeveloper\system).
[5]
Minor patches
[6]
Chapter 1
Third-party extensions
For all extensions, you need to start Check for Updates to see what's available.
To do this, go to Help | Features. Just follow the dialog to find the updates that
you require.
You can initially elect to see just the third-party updates, or all updates available,
by selecting all options, as shown in the following screenshot:
The database drivers for some of the non-Oracle databases are located in Third Party
SQL Developer Extensions. The Third Party update center also includes a selection
of customer developed SQL Developer extensions. The customer extensions are
developed, supported, and updated by the customer involved; they are not tested,
certified, or supported by Oracle.
[7]
As with all software downloads from the Internet, you are required to read and
accept the license agreements. The Check for Updates utility directs you to the
appropriate licenses before downloading the software. If the updates are from
Oracle, you will need to provide your Oracle Technology Network sign-on details.
User-defined
snippets
SQL history
Linux: ~/.sqldeveloper/SqlHistory.xml
Mac OS X: /Users/<Your user>/Library/Application
Support/ SQLDeveloper/ SqlHistory.xml
[8]
Chapter 1
Code
templates
SQL
Developer
user
preferences
If you want to prevent other users from accessing your user-specific SQL Developer
information, you must ensure that appropriate permissions are set on the directory
where that information is stored or on a directory above it in the path hierarchy. For
example, in a Windows system you may want to ensure that the SQL Developer
folder and the \<user-name>\Application Data\SQL Developer folder under
Documents and Settings are not sharable, whereas on a Linux or Mac OS X system
you may want to ensure that the ~/.sqldeveloper directory is not world-readable.
Sharing preferences.
Preferences are set for your local environment and are therefore not shared globally
between teams. However, you can export the SQL Formatter preferences set. This
allows you to share the settings between team members and ensure that you all
code to the same settings. To export your SQL Formatter settings, go to Tools |
Preferences and expand the Database node in the tree. Select SQL Formatter, and
you can now export or import previous saved settings.
Oracle JDeveloper
Most of SQL Developer is integrated into Oracle JDeveloper, which means you need
to install JDeveloper to access and use the SQL Developer components. Having SQL
Developer as part of JDeveloper means that if you are building Java applications and
working with the Fusion Middleware platform, you can access and work with the
Oracle Database without an additional install of SQL Developer. JDeveloper does
not consume all of the extensions for SQL Developer (for example, extensions like
Migrations and Versioning are not included).
[9]
Oracle Database 12c ships with SQL Developer 3.2.20.09 to work with 12c features like
Multitenant stuff, Redaction, SQL Translation Framework, and Identity Columns.
Troubleshooting
It seems ominous to provide a section on troubleshooting at the start of a book! If
you accept the fact that software can get in a tangle sometimes, either if you use the
product as it's not designed, or perhaps include extensions that you'd prefer not to
have and the product is no longer behaving as expected, then a few hints on how
to escape that tangle can be useful.
[ 10 ]
Chapter 1
Removing extensions
If you have created your own extensions, or have downloaded and installed other
extensions that you no longer require, then go to Tools | Features and select
Extensions from the tree. Here, you see that SQL Developer includes a number of
default extensions, such as the Oracle TimesTen extension. In addition, any extension
that you have included is listed here. You can deselect extensions here and the
product will no longer have access to them. This does not delete the files installed
for the extension. You will need to manually delete any files downloaded for that
to happen. However, it does mean that you can restart the product and see if the
extension is the root of the problem.
[ 11 ]
Select Default from the dialog to reset the keyboard accelerators to the shipped
settings. This also replaces any settings you have added.
In releases prior to SQL Developer 2.1, the Shortcut Keys are called
Accelerators. In releases post 2.1, to reset the keys, select Load Preset.
[ 12 ]
Chapter 1
A quick overview
Let's start with a walk-through of the product. This book is all about SQL Developer
4.1, using the product, and getting to know it. You may well ask yourself why there
is a need for a book if we can walk through the product in twenty minutes or less.
Generally only 10% of the SQL Developer features are used by people on average,
but their sweet spots are probably different. By spending a little time delving into
a number of areas of the product, you can start laying down a map of how the
pieces connect and provide a base that you can drill down into later and become
more productive.
Sample schemas
To follow the examples in the book, you need access to SYSTEM schema of a
database and some of the shipped sample schemas, HR, OE, SH, PM, and IX
available in Oracle Database 9i, 10g, 11g, or 12c. Specifically, this book uses the
sample schemas shipped with Oracle Database 11g R2 & 12c.
There are two ways to install the sample schema. The first way is when you install
the database. You can elect to have the sample schema installed at that point.
Second, if you have not installed these, then you can locate the sample schema in the
$ORACLE_HOME/demo/schema folder and follow the instructions on installing them
using the Oracle online documentation. Not all of these schemas are available for
Oracle Express Edition. In this chapter, we use SYSTEM to verify that the HR schema
is unlocked, and then we use the HR sample schema, which is available in Oracle
Express Edition.
[ 13 ]
You are now connected as SYSTEM. Use this connection to verify your other
users, by continuing with following steps.
[ 14 ]
Chapter 1
4. Select the new connection you have created, expand the node, and scroll
down to Other Users.
5. Expand Other Users and find the user HR. Right-click on it and select Edit
User. Verify that the account for HR is unlocked and the Password has not
expired, that is, the properties Account is Locked and Password Expired are
deselected. If either of these is selected, deselect them. You can change the
password for HR at this point too. It's good practice to modify the passwords
of the shipped sample schemas once you have unlocked them.
Now you are really ready to begin.
1. Once again, select Connections, right-click and select New Connection.
2. Give the connection a name (for example, HR_11g).
3. Provide the Username (HR) and a Password. If you are working on Oracle
Database 11g, be aware that passwords are now case sensitive.
4. Select the Save Password checkbox. This makes life easy while you are
working with SQL Developer. Passwords are stored in an encrypted file.
However, you should always be aware of saving passwords and possible
security implications this may have.
5. Use the Basic connection. This requires no more detail than the location of
the database and the SID, details you have.
6. Click on Test to test the connection.
7. Click on Connect.
[ 15 ]
The output of both commands appears in the Script Output tab, which appears
below the SQL Worksheet (as seen in the previous screenshot). Both commands
are handled by a few simple clicks of the mouse in SQL Developer.
Select and expand the HR_11g connection in the Connections navigator. Expand
the Tables node and select DEPARTMENTS.
The DEPARTMENTS tab now opens, displaying a list of the column names
and details. These are the same details as given by the DESC (describe) SQL*Plus
command that you entered in the SQL Worksheet. It also provides additional
detail, such as the Primary Key and column comments.
[ 16 ]
Chapter 1
Select the Data tab and notice that you now see the output from your second
command. These two tabs are included with a number of other tabs, each with
additional details about the DEPARTMENTS table. You would need to write a
number of SQL queries in order to get the additional detail from the data dictionary
if you were working in SQL*Plus.
Select the EMPLOYEES table. Notice that the new table, EMPLOYEES, immediately
replaces the previous DEPARTMENTS table with its details. Select the Triggers tab,
and select one of the triggers. The trigger and related trigger detail is displayed in a
master-detail window, as shown in the following screenshot:
[ 17 ]
Once again, you get feedback, this time in the Messages Log, as shown in the
following screenshot:
Running reports
To run your report, perform the following steps:
1. Select the Reports navigator and expand the Data Dictionary Reports
node. Expand the Table node and review the available reports. Expand
Constraints and select the Unique Constraints report.
2. As you select the report, a dialog displays requesting the Connection name.
Select the connection you created, HR_11g, and click on OK.
[ 18 ]
Chapter 1
3. An Enter Bind Values dialog now appears, requesting the table name as an
input parameter. Click on Apply to accept the default, which in this case,
means all tables:
[ 19 ]
Run the same report for any user by selecting the Connections
drop-down list on the right-hand side.
The two main navigators, Connections and Reports, are presented in a tabbed
window. These and other navigators, such as the Versioning Navigator, are
available through the main View menu. You can also open windows such as
Snippets, Recent Objects, and Find DB Objects using the View menu.
Any navigators that you open during a session, and that are still
open when you close the product, are automatically opened when
you restart the product.
[ 20 ]
Chapter 1
You can rearrange tabbed windows by selecting and dragging the tab into place.
Once any window is minimized, roll your mouse over the minimized tab to display
a floating window that stays active while your mouse lies over it and rolls back
into place when you move off. This is very useful when working with temporary
windows such as Snippets and Find DB Object. The following screenshot shows
the floating window for the Snippets dialog. If you roll the mouse over the area, you
can work in the window (for example, navigating about until you have located the
snippet of code you are after, and then dragging the code onto the worksheet). The
window will minimize out of the way once you have moved off it.
[ 21 ]
You can undock the floating window, move it off to one side, and keep it undocked
while you work with the SQL Worksheet. In a dual-monitor setup, you can drag the
floating window onto one monitor, while working with the SQL Worksheet on the
other monitor.
Tiling windows
Once you start working with connections, you will have more windows and tabs
to deal with, especially if you have more than one connection created.
1. Select the HR_11g connection created in the previous section, expand the
connection and Tables node, and select EMPLOYEES.
2. In the table definition window, select the pin button (Freeze View),
as shown in the following screenshot, to freeze the view.
[ 22 ]
Chapter 1
Vertically:
Horizontally:
[ 23 ]
Splitting documents
When you tile windows, you can compare the details of two tables. However, as each
table has a selection of tabs, it's useful to be able to review details in the tabs without
having to switch back and forth between tabs. As is true for other layout features,
you can split the document using a menu or by drag-and-drop. Each of the object
definitions tabbed displays has a drag bar on the top and bottom right that you
can select and drag to split the window horizontally, or vertically, as shown in the
following screenshot:
Maximizing detail
Almost all of the tabs in SQL Developer will maximize when double-clicked. There
are a few that do not follow this rule, such as the tabs related to the SQL Worksheet.
In general, this works for top-level tabs, which is any tab you can undock and move
about, and not for secondary tabs. To maximize a tab, double-click on the tab. A
second double-click will reverse the process.
Double-click on the tab to maximize a top-level tab. Double-click again to
revert to the previous layout.
[ 24 ]
Chapter 1
The example in the following screenshot displays the standard docked Connections
and Reports windows to the left. The Reports window, by default, docks below the
connections. We have also docked the Snippets window to the right. These windows
fill the columns to the left and right, leaving a central window for the editors and
log files.
The layout is controlled by the window layout set in the preferences. Go to Tools |
Preferences under the Environment node in the tree select Dockable Windows. The
default layout, and the one that matches the example in the previous screenshot, is
shown in the following screenshot:
[ 25 ]
Each of the little curved arrows on the diagram is clickable, and as such controls
the positioning of the windows. Clicking on the arrow extends or contracts the
area taken up by the docked window.
In our example, and in the default SQL Developer environment, there is no
full-docked window across the top of the screen. However, if you drag a window
into the docked position below the main tool bar, it would stretch across the screen.
If you find your windows are in a muddle, first verify that the Dockable Windows
layout is what you want, and then drag the various dockable windows back into
place. Some suggestions on the SQL Developer forum are to remove the system
folder (it works, but that's an extreme solution).
[ 26 ]
Chapter 1
Summary
You've started and should now have SQL Developer installed. You should have a
few connections created and an initial idea of how to navigate around the product.
You are now set to learn a lot more about SQL Developer. From here, you can delve
into different chapters, focusing on the areas you're most interested in.
In the next chapter, you will learn how to browse different types of objects and
use SQL Developer to look at them in greater detail. We'll review the different
editors and dialogs available and you'll learn how to manage what you see using
preferences. You will also discover the different ways in which you can create
objects and learn how to manipulate the data.
[ 27 ]
www.PacktPub.com
Stay Connected: