Using the SQL Worksheet |
You can use the SQL Worksheet to enter and execute SQL, PL/SQL, and SQL*Plus statements. You can specify any actions that can be processed by the database connection associated with the worksheet, such as creating a table, inserting data, creating and editing a trigger, selecting data from a table, and saving that data to a file.
When you connect to a database, a SQL Worksheet window for that connection is automatically opened. You can also display a SQL Worksheet by selecting Tools and then SQL Worksheet, or by clicking the Use SQL Worksheet icon under the menu bar. In the Select Connection dialog box, select the database connection to use for your work with the worksheet. (You can also use that dialog box to create and edit database connections.)
The SQL Worksheet has the user interface shown in the following figure:
SQL Worksheet toolbar (under the SQL Worksheet tab): Contains icons for the following operations:
Execute Statement executes the statement at the mouse pointer in the Enter SQL Statement box. The SQL statements can include bind variables (but not substitution variables) of type VARCHAR2 (although in most cases, VARCHAR2 is automatically converted internally to NUMBER if necessary); a pop-up box is displayed for entering bind variable values.
Run Script executes all statements in the Enter SQL Statement box using the Script Runner. The SQL statements can include substitution variables (but not bind variables) of type VARCHAR2 (although in most cases, VARCHAR2 is automatically converted internally to NUMBER if necessary); a pop-up box is displayed for entering substitution variable values.
Commit writes any changes to the database, and ends the transaction; also clears any output in the Results and Script Output panes.
Rollback discards any changes without writing them to the database, and ends the transaction; also clears any output in the Results and Script Output panes.
Cancel stops the execution of any statements currently being executed.
SQL History displays a dialog box with information about SQL statements that you have executed. You can save statements to a file, or append to or overwrite statements on the worksheet (see SQL History List).
Execute Explain Plan generates the execution plan for the statement (internally executing the EXPLAIN PLAN statement). To see the execution plan, click the Explain tab. For more information, see Execution Plan.
Clear erases the statement or statements in the Enter SQL Statement box.
To the right of these icons is a drop-down list for changing the database connection to use with the worksheet.
The right-click menu includes the preceding SQL Worksheet toolbar operations, plus the following operations to support file-oriented development:
Open File opens a selected SQL script file in the Enter SQL Statement box.
Save File saves the contents of the Enter SQL Statement box to a file.
Print File prints the contents of the Enter SQL Statement box.
Enter SQL Statement: The statement or statements that you intend to execute. For multiple statements, each non-PL/SQL statement must be terminated with either a semicolon or (on a new line) a slash (/), and each PL/SQL statement must be terminated with a slash (/) on a new line. SQL keywords are automatically highlighted. To format the statement (capitalizing the names of statements, clauses, keywords, and so on), right-click in the statement area and select Format SQL.
You can drag some kinds of objects from the Connections navigator and drop them into the Enter SQL Statement box:
If you drag and drop a table or view, a SELECT statement is constructed with all columns in the table or view. You can then edit the statement, for example, modifying the column list or adding a WHERE clause.
If you drag and drop a function or procedure, a snippet-like text block is constructed for you to edit when including that object in a statement.
Tabs display panes with the following information:
Results: Displays the results of the most recent Execute Statement operation.
Explain: Displays the output if you clicked the Explain Execution Plan icon (see Execution Plan).
Script Output: Displays the output if you clicked the Run Script icon (see Script Runner).
DBMS Output: Displays the output of DBMS_OUTPUT package statements (see DBMS Output Pane).
OWA Output: Displays Oracle Web Agent (MOD_PLSQL) output (see OWA Output Pane).
Related Topics
SQL*Plus Statements Supported and Not Supported in SQL Worksheet
Using Snippets to Insert Code Fragments
Using the SQL Worksheet for Queries (tutorial)
SQL Developer Concepts and Usage
The SQL Worksheet supports some SQL*Plus statements. SQL*Plus statements must be interpreted by the SQL Worksheet before being passed to the database; any SQL*Plus that are not supported by the SQL Worksheet are ignored and not passed to the database.
The following SQL*Plus statements are supported by the SQL Worksheet:
@ @@ acc[ept] conn[ect] def[ine] desc[ribe] doc[ument] exec[ute] exit (Stops execution and reinstates the specified connection) pro[mpt] quit (Stops execution and reinstates the specified connection) rem[ark] sta[rt] undef[ine] whenever
The following SQL*Plus statements are not supported by the SQL Worksheet:
a[ppend] archive attr[ibute] bre[ak] bti[tle] c[hange] cl[ear] col[ulmn] comp[ute] copy del disc[onnect] ed[it] get help ho[st] i[nput] l[ist] newpage oradebug passw[ord] pau[se] print r[un] recover repf[ooter] reph[eader] sav[e] sho[w] shu[tdown] spo[ol] startup store timi[ng] tti[tle] var[iable]
Related Topics
The script runner emulates a limited set of SQL*Plus features. If you do not have SQL*Plus on your system, you can often enter SQL and SQL*Plus statements and execute them by clicking the Run Script icon. The Script Output pane displays the output.
The SQL*Plus features available in the script runner include @, @@, CONNECT, EXIT, QUIT, UNDEFINE, WHENEVER, and substitution variables. For example, to run a script named c:\myscripts\mytest.sql, type @c:\myscripts\mytest in the Enter SQL Statement box, and click the drop-down next to the Execute Statement icon and select Run Script.
The following considerations apply to using the SQL Developer script runner:
You cannot use bind variables. (The Execute SQL Statement feature does let you use bind variables of type VARCHAR2, NUMBER, and DATE.)
For substitution variables, the syntax &&variable assigns a permanent variable value, and the syntax &variable assigns a temporary (not stored) variable value.
For EXIT and QUIT, commit is the default behavior, but you can specify rollback. In either case, the context is reset: for example, WHENEVER command information and substitution variable values are cleared.
DESCRIBE works for most, but not all, object types for which it is supported in SQL*Plus.
For SQL*Plus commands that are not supported, a warning message is displayed.
SQL*Plus comments are ignored.
If you have SQL*Plus available on your system, you may want to use it instead of the script runner. To start SQL*Plus from SQL Developer, click Tools and then SQL*Plus. For information about SQL*Plus, see Using SQL*Plus.
Related Topics
The Execute Explain Plan icon generates the execution plan, which you can see by clicking the Explain tab. The execution plan is the sequence of operations that will be performed to execute the statement. An execution plan shows a row source tree with the hierarchy of operations that make up the statement. For each operation, it shows the ordering of the tables referenced by the statement, access method for each table mentioned in the statement, join method for tables affected by join operations in the statement, and data operations such as filter, sort, or aggregation.
In addition to the row source tree, the plan table displays information about optimization (such as the cost and cardinality of each operation), partitioning (such as the set of accessed partitions), and parallel execution (such as the distribution method of join inputs). For more information, see the chapter about using EXPLAIN PLAN in Oracle Database Performance Tuning Guide.
Related Topics
The PL/SQL DBMS_OUTPUT package enables you to send messages from stored procedures, packages, and triggers. The PUT and PUT_LINE procedures in this package enable you to place information in a buffer that can be read by another trigger, procedure, or package. In a separate PL/SQL procedure or anonymous block, you can display the buffered information by calling the GET_LINE procedure. The DBMS Output pane is used to display the output of that buffer. This pane contains icons and other controls for the following operations:
Enable/Disable DBMS Output: Toggles the SET SERVEROUTPUT setting between ON and OFF. Setting server output ON checks for any output that is placed in the DBMS_OUTPUT buffer, and any output is displayed in the pane.
Clear: Erases the contents of the pane.
Save: Saves the contents of the pane to a file that you specify.
Print: Prints the contents of the pane.
Buffer Size: For databases before Oracle Database 10.2, limits the amount of data that can be stored in the DBMS_OUTPUT buffer. The buffer size can be between 1 and 1000000 (1 million).
Poll: The interval (in seconds) at which SQL Developer will check the DBMS_OUTPUT buffer to see if there is data to print. The poll rate can be between 1 and 15.
Related Topics
OWA (Oracle Web Agent) or MOD_PLSQL is an Apache (Web Server) extension module that enables you to create dynamic Web pages from PL/SQL packages and stored procedures. The OWA Output pane enables you to see the HTML output of MOD_PLSQL actions that have been executed in the SQL Worksheet. This pane contains icons for the following operations:
Enable/Disable OWA Output: Enables and disables the checking of the OWA output buffer and the display of OWA output to the pane.
Clear: Erases the contents of the pane.
Save: Saves the contents of the pane to a file that you specify.
Print: Prints the contents of the pane.
Related Topics