Professional Documents
Culture Documents
Big Data Among its other features, Oracle SQL Developer provides database developers and DBAs with a comprehensive environment for creating, editing,
compiling, running, and debugging PL/SQL program units. Its editing capabilities include customizable syntax highlighting, bookmarks, code
Security
completion, code folding, and search/replace. The debugging features are especially useful for working with more-complex packages, debugging
Enterprise Architecture while stepping through a series of procedures, and remote debugging (debugging initialized by an external client or program).
Digital Experience This column introduces Oracle SQL Developer's key features for working with PL/SQL in the database. The column's examples use the sample HR
Service-Oriented Architecture schema and the EMP_FETCHER packageboth available in the default database installationand the EMP_REC object type, which you'll create. By
working through the examples, you'll
Virtualization
Run PL/SQL procedures, functions, and packages
Mobile Computing
Edit PL/SQL code
Compile PL/SQL
Getting Started
Follow these steps to establish the basic setup for this column's examples:
5. Press F5 (or click the Run Script button) to create the EMP n _REC object type.
6. Click the Clear button or press Ctrl-D to clear the Enter SQL Statement text box.
7. Create the package specification and body, respectively, by entering the code in Listings 2 and 3 into the Enter SQL Statement text box and
running the script for each. (Another way to create a new package is to expand the HR_ORCL node in the Connections Navigator, select Packages ,
and right-click to invoke the New Package ... menu.)
To see the new package in the Connections Navigator, expand the HR_ORCL node and then expand the Packages node. Figure 1 shows the SQL
worksheet and the Connections Navigator as they should look after you complete the preceding steps.
https://www.oracle.com/technetwork/topics/o67sql-101793.html 26/12/2018
SQL Developer: Working with PL/SQL Page 2 of 4
In the PL/SQL block, change EMP_NO := NULL; to EMP_NO := 201; and click OK . In your EMPLOYEES table, 201 is an existing employee, so
the package executes and completes with minimal feedback. For comparison, run the package again for EMP_NO := 2001; (a nonexistent
employee). On completion, you should see a "no data found" error message.
In this example, the function retrieves information that a procedure could use. You can use the anonymous block in the Run PL/SQL dialog box to
see that detail. The block contains the lines
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('v_Return
= ' || v_Return);
By uncommenting and modifying the second of these two lines, you can display the output. The function returns a record, or set of elements, so you
must specify which value(s) you want to output. You can select from all the values in the record. This example uses the LAST_NAME, HIRE_DATE,
and SALARY values. Expand the Types node in the Connections Navigator, and select EMP_REC . Review the code. Return to the EMP_FETCHER
package, and run it again. Change EMP_NO := 2001 back to EMP_NO := 201 . Then replace the line
--DBMS_OUTPUT.PUT_LINE('v_Return
= ' || v_Return);
with
DBMS_OUTPUT.PUT_LINE('Employee '|| emp_no || ' is ' || v_return.LAST_NAME);
DBMS_OUTPUT.PUT_LINE('Hired on the '|| v_return.HIRE_DATE || ' and earns '|| v_return.salary);
Click OK , and view the output in the Running - Log window.
Oracle SQL Developer's Code Insight feature includes both Parameter Insight and Completion Insight. Parameter Insight displays a context-sensitive
pop-up menu that provides you with a list of procedures or functions in a package. Completion Insight displays a context-sensitive pop-up menu that
provides you with a list of possible completions at the insertion point, which you can use to autocomplete the code you are editing in either the code
editor or the SQL worksheet. By default, if you type a period (.) and pause for more than one second, Completion Insight is invoked automatically.
(You can change the delay time by setting a preference.) To invoke it manually, press Ctrl-space. To try Completion Insight, type SELECT HR . in
Oracle PL/SQL Code Editor and then pause. Completion Insight provides a pop-up menu that displays all the objects HR owns. Click an object in the
list to add it to your code at the insertion point.
Possibly more useful is a narrowed-down insight search, such as for the table alias. Type
SELECT FROM EMPLOYEES e
in the code editor. Then type e in the space between SELECT and FROM and press Ctrl-space. After a pause, a list of the columns in the
EMPLOYEES table pops up.
A full discussion of Oracle SQL Developer's editing features would be too extensive for this space. I encourage you to experiment with Code Insight
and other Oracle PL/SQL Code Editor features, such as parenthesis matching (click on a set of parentheses, and note the highlighting), before
compiling your code.
When you're ready to compile, click the Compile button or press Ctrl-Shift-F9. Any compilation errors display in the Compiler-Log window. Double-
click on errors to navigate to the error source.
To debug any code, you must set one or more breakpoints and then select Compile
for Debug . This compiles the PL/SQL with PL/SQL library units for debugging. If Next Steps
you then run the code in debug mode, it runs to the first breakpoint. Breakpoints
are customizable; for example, you can associate breakpoints with any unhandled
exception or with specific Oracle Database exceptions. (If you are debugging LEARN more about Oracle SQL Developer
PL/SQL in a database version prior to Oracle9 IDatabase Release 2, you must set
the Migration -> PL/SQL Debugger preference to Use Probe Debugger to debug
FIND more PL/SQL examples and samples in the online
PL/SQL .)
documentation
Oracle SQL Developer's main debugging features let you control your program's
execution. For example, you can step into each line of code or step over a
DISCUSS online documentation
procedure or function. Oracle SQL Developer displays the values of variables and
data as you step though the code. Stepping over code is useful when you're
debugging a procedure that calls a function. You don't necessarily want to go CREATE a database connection
through all the lines of code in the function, so you step over it and back into the
troublesome procedure.
Remotely debugging PL/SQL with Oracle SQL Developer means that you initiate the debug action from a client external to Oracle SQL Developer.
External clients include PL/SQL Web applications, Oracle Application Express applications, and SQL*Plus sessions. Remote debugging requires
some manual steps: starting the Oracle SQL Developer debugger listener and attaching to that listener via the database session you want to debug.
(Remote debugging is not available for databases prior to Oracle9 I Database Release 2.)
1. In Oracle SQL Developer, set up a connection to the database where the PL/SQL is resident. Use the same HR_ORCL connection and
EMP_FETCHER package you used earlier. Chat
2. Select the HR_ORCL connection in the Connections Navigator, and then right-click and select Remote Debug . This invokes the Listen for JPDA
dialog box.
3. Enter a port and the IP address for the server. You should now see a new Run Manager window displaying the Debug Listener host information.
(You can set Tools -> Preferences -> Debugger -> Prompt for Debugger Host for Database Debugging when connecting across firewalls or virtual
private network [VPN] sessions.)
4. In the Connections Navigator, select the EMP_FETCHER package body, and then right-click and select Edit... to open Oracle PL/SQL Code
Editor. Click in the left margin next to FUNCTION GET_EMP... to set a breakpoint.
5. Click Compile for Debug , as shown in Figure 2. 6. You are now ready to start the remote debugging process from Oracle SQL Developer's
perspective. You need to get the external clientin this case SQL*Plusready. Start a SQL*Plus session for the same database user, and enter the
following, substituting the IP address and port you used when you started the remote connection from Oracle SQL Developer:
exec DBMS_DEBUG_JDWP.CONNECT_TCP ('127.0.0.1', 4000)
https://www.oracle.com/technetwork/topics/o67sql-101793.html 26/12/2018
SQL Developer: Working with PL/SQL Page 3 of 4
DECLARE
EMP_NO NUMBER;
v_Return HR.EMP_REC;
BEGIN
v_Return := EMP_FETCHER.GET_EMP(201);
END;
/
8. Control now passes to Oracle SQL Developer, and you can step through the code. The process at this point is the same for remote debugging as
for local debugging.
Various debug windows are now active. They all have a role, but the immediately important ones are
The Debugging window, which includes the program execution controls. Start debugging, by clicking the Step Into icon.
The code editor, which shows the execution point. As you step through the code, mouse flyover tool tips display the name and value of the variable
under the pointer. Keep clicking Step Into until you reach the line EMP_RTN:= EMP_REC.... At this point, let your mouse hover over one of the
EMP_FOUND values to see the tool tip, as shown in Figure 3.
The Data window displays all variables that are currently in scope. Still with the execution point at EMP_RTN := EMP_REC..., select the Data tab and
expand the EMP_FOUND node. The record is now populated. At this point, you can watch and modify variables to see the impact on your procedure.
Chat
https://www.oracle.com/technetwork/topics/o67sql-101793.html 26/12/2018
SQL Developer: Working with PL/SQL Page 4 of 4
9. Continue to step through the code until your procedure completes, control is returned to the external client, and the debug session is finished.
Conclusion
With Oracle SQL Developer, you can browse and edit database objects, query data, and run reports. One of the useful features in Oracle SQL
Developer is its ability to edit, compile, run, and debug PL/SQL. Oracle SQL Developer supports both local and remote debugging; the remote-
debugging capabilities let you kick off PL/SQL debugging sessions inside Oracle SQL Developer from external clients (such as SQL*Plus).
Sue Harper (sue.harper@oracle.com) is an Oracle senior principal product manager based in London.
© Oracle Site Map Terms of Use and Privacy Preferencias para cookies Ad Choices
Chat
https://www.oracle.com/technetwork/topics/o67sql-101793.html 26/12/2018