Executing SQL Statements in the Code Editor

The code editor in the SQL page enables you to run SQL statements, PL/SQL scripts, and JavaScript code. The main features include in-context code completion, syntax highlighting, and error debugging.

You can enter SQL and PL/SQL statements to specify actions such as creating a table, inserting data, selecting data, or deleting data from a table. SQL keywords are automatically highlighted. For multiple statements, you must terminate:

  • Each non-PL/SQL statement with either a semicolon (;) or a slash (/) on a new line
  • Each PL/SQL statement with a slash (/) on a new line

The PL/SQL editor is triggered when opening the following object types: Functions, Procedures, Packages and Types. This editor helps you detect errors in your PL/SQL code during compilation. The output includes details such as the specific line and column where the error is detected, along with a link to go to the relevant position in the code block.

The JavaScript worksheet mode supports the Multilingual Engine syntax in Oracle Database release 21c. For more details, see Support for Multilingual Engine.

For SQL*Plus and SQLcl statements supported in the worksheet, see Supported SQL*Plus and SQLcl Commands in SQL Worksheet.

Use the Consumer Group drop-down list to select the consumer group to run your SQL or PL/SQL code. The values in the drop-down list match the database services available when connecting to the database. This feature is available only if you have the EXECUTE privilege on the CS_SESSION package.

If you press Ctrl+Space, the editor provides you with a list of possible completions at the insertion point that you can use to autocomplete code that you are editing. This list is based on the code context at the insertion point.

The editor offers a comprehensive list of commands available through the Command Palette. To open the Command Palette, press Ctrl+Shift+P. For a list of keyboard shortcut keys, see Keyboard Shortcuts.

An error in the code is signified by a red dot in the left gutter and a squiggle line beneath the specific text. When you hover over it, you see a pop-up displaying possible fixes for resolving the error.

You can set code editor preferences using the Preferences option available in the top-right user drop-down list. Some of the code editor options that you can customize are Theme (Light, Dark and High contrast dark), Font size and family, Tab size, Word wrap, Ruler, Line numbers and so on.

The SQL toolbar contains icons for the following operations:

  • Worksheet drop-down list

    • Open: Opens a file from the browser or device.
    • Open Recent: Displays the recently accessed files. If there are more than five files in the recent list, then a More link is displayed for viewing the additonal files.
    • Save As: Saves a file to the browser or device.
  • New File
    • Select Worksheet to create a worksheet.
    • Select PL/SQL to create a PL/SQL object type. The editor switches to a PL/SQL mode.
    • Select JavaScript to create a JavaScript file. The editor switches to a JavaScript mode and (JS) is added to the file name.
  • Open opens a file from your browser or device. To open a file from your device, in the Open File slider, click Open File and browse to select the file, or drag and drop the file into the slider.
  • Run Statement

    • Run Statement executes the selected statements or the statement at the mouse pointer in the worksheet editor. The SQL statements can include bind variables and substitution variables of type VARCHAR2 (although in most cases, VARCHAR2 is automatically converted internally to NUMBER if necessary). A dialog box is displayed for entering variable values.

    • Run Statement Without Pagination executes the selected statements without wrapping it inside a ROW_NUMBER()OVER analytic function to implement paging. This means the query is run 'as is' in the worksheet, and only fetches the first 256 rows.
  • Run Script

    • Run as SQL Script executes all statements in the worksheet editor using the Script Runner. 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 dialog box is displayed for entering bind variable values.

    • Run as JavaScript executes the code as a JavaScript file. This option is used only with JavaScript code. If the JavaScript code is added to a PL/SQL block, then select "Run as SQL Script" to execute the script.

  • Compile (for PL/SQL toolbar) performs a PL/SQL compilation of the subprogram.
  • Create Chart creates a chart for the corresponding SQL statement entered in the editor. In contrast, you can partially highlight a subquery and create a chart. A slider window is displayed for entering the chart parameters. For a description of the fields, see Creating or Editing a Chart.

    If the SQL statement is syntactically incorrect or incomplete, an error/warning notification is displayed.

  • Explain Plan generates the execution plan for the statement (internally executing the EXPLAIN PLAN statement). The execution plan is automatically displayed in the Explain Plan tab in the worksheet output pane. See Viewing the SQL Output

  • Autotrace runs the statement and collects run time statistics and the actual execution plan. The Autotrace output is displayed in the Autotrace tab in the worksheet output pane. Currently, there are no preferences available.

  • Download Editor Content downloads the content of the worksheet as a SQL file to the local system.

  • Format formats the SQL statement in the editor, such as capitalizing the names of statements, clauses, keywords, and adding line breaks and indentation.

  • Clear removes the statements from the editor.

  • Tour provides a guided tour of the worksheet highlighting salient features and providing information that is useful if you are new to the interface.

  • Help provides context-related help and provides a link to the help documentation.

  • Open in Fullscreen opens the editor in full screen mode.

About Session State in Database Actions

In Database Actions, a connection to the database is stateless.

In a stateless environment, each HTTPS request from a client maps to a new database session. Therefore, a session begins and ends with every SQL statement or script execution.

As the session state is not maintained, session attributes do not persist and commands such as ROLLBACK and COMMIT do not apply. If a SQL statement or script executes successfully, an implicit commit is performed. If it executes with an error, an implicit rollback is performed.

Therefore, when needed, include the ROLLBACK and COMMIT commands or session attributes in the PL/SQL code block that is sent to the database for a session.

The only configuration commands that persist during a session in Database Actions are:

  • SET DEF[INE] <ON|OFF|prefix_character>
  • SET ESC[APE] <ON|OFF|escape_character>
  • SET TIMI[NG] <ON|OFF>

Keyboard Shortcuts

This section lists the keyboard shortcuts for various commands in the SQL page.

Table 3-1 Keyboard Shortcuts

Windows MacOS Description

Ctrl + Enter

Cmd + Enter

Runs the code as query.

Alt + Tab

Option + Tab

Focus next element.

Ctrl+ Esc / Escape

Cmd + Esc / Escape

Remove focus from editor.

Ctrl + Down Arrow

Cmd + Down Arrow

Moves to the next SQL code from history.

Ctrl + Up Arrow

Cmd + Up Arrow

Moves to the previous SQL code from history.

Ctrl + S

Cmd + S

Saves the current worksheet.

Ctrl + O

Cmd + O

Opens the worksheet browser dialog.

Ctrl + I

Cmd + I

Downloads the content of the editor.

F1 Fn + F1 Opens the help topic.

Shift + Esc

Shift + Esc

Focus previous element.

F5

Fn + F5

Runs code as script.

F6

Fn + F6

Shows Autotrace.

F10

Fn + F10

Shows Explain Plan.

F11

Fn + F11

Creates a chart.

Ctrl + B

Cmd + B

Opens the "Convert Case" drop-down list.

Ctrl + F7

Cmd + Fn + F7

Formats code in the editor.

Ctrl + Space

Ctrl + Space

Autocompletes code (shows hints).

The following table lists the keyboard shortcuts for commands in the Command Palette.

Table 3-2 Command Palette Keyboard Shortcuts

Windows MacOS Description
Ctrl + Alt + Up Cmd + Option + Up Add Cursor Above
Ctrl + Alt + Down Cmd + Option + Down Add Cursor Below
Shift + Alt + I Shift + Option + I Add Cursors to Line Ends
Ctrl + K Ctrl + C Cmd + K Cmd + C Add Line Comment
Ctrl + D Cmd + D Add Selection To Next Find Match
Shift + Alt + Down Shift + Option + Down Copy Line Down
Shift + Alt + Up Shift + Option + Up Copy Line Up
Ctrl + U Cmd + U Cursor Undo
- Cmd + Backspace Delete All Left
- Ctrl + K Delete All Right
Ctrl + Shift + K Shift + Cmd + K Delete Line
Shift + Alt + Right Shift + Ctrl + Cmd + Right Expand Selection
Ctrl + F Cmd + F Find
Enter Enter Find Next
Ctrl + F3 Cmd + Fn + F3 Find Next Selection
Shift + Enter Shift + Enter Find Previous
Ctrl + Shift + F3 Shift + Cmd + Fn + F3 Find Previous Selection
- Cmd + E Find With Selection
Ctrl + Shift + [ Option + Cmd + [ Fold
Ctrl + K Ctrl + 0 Cmd + K Cmd + 0 Fold All
Ctrl + K Ctrl + / Cmd + K Cmd + / Fold All Block Comments
Ctrl + K Ctrl + 8 Cmd + K Cmd + 8 Fold All Regions
Ctrl + K Ctrl + 1 Cmd + K Cmd + 1 Fold Level 1
Ctrl + K Ctrl + 2 Cmd + K Cmd + 2 Fold Level 2
Ctrl + K Ctrl + 3 Cmd + K Cmd + 3 Fold Level 3
Ctrl + K Ctrl + 4 Cmd + K Cmd + 4 Fold Level 4
Ctrl + K Ctrl + 5 Cmd + K Cmd + 5 Fold Level 5
Ctrl + K Ctrl + 6 Cmd + K Cmd + 6 Fold Level 6
Ctrl + K Ctrl + 7 Cmd + K Cmd + 7 Fold Level 7
Ctrl + K Ctrl + [ Cmd + K Cmd + [ Fold Recursively
Ctrl + Shift + \ Shift + Cmd + \ Go to Bracket
Ctrl + G Ctrl + G Go to Line...
Alt + F8 Option + Fn + F8 Go to Next Problem(Error, Warning, Info)
F8 Fn + F8 Go to Next Problem in Files (Error, Warning, Info)
F7 Fn + F7 Go to Next Symbol Highlight
Shift + Alt + F8 Shift + Option + Fn + F8 Go to Previous Problem (Error, Warning, Info)
Shift + F8 Shift + Fn + F8 Go to Previous Problem in Files (Error, Warning, Info)
Shift + F7 Shift + Fn + F7 Go to Previous Symbol Highlight
Ctrl + ] Cmd + ] Indent Line
Ctrl + Shift + Enter Shift + Cmd + Enter Insert Line Above
- Ctrl + J Join Lines
Ctrl + K Ctrl + D Cmd + K Cmd + D Move Last Selection To Next Find Match
Alt + Down Option + Down Move Line Down
Alt + Up Option + Up Move Line up

F1 (All browsers)

Ctrl + Shift + P (Google Chrome only)

Fn + F1 Open Command palette
Ctrl + [ Cmd + [ Outdent Line
Ctrl + K Ctrl + U Cmd + K Cmd + U Remove Line Comment
Ctrl + H Option + Cmd + F Replace
Ctrl + Shift + . Shift + Cmd + . Replace with Next Value
Ctrl + Shift + , Shift + Cmd + , Replace with Previous Value
Ctrl + Shift + L Shift + Cmd + L Select All Occurrences of Find Match
Alt + F1 Option + Fn + F1 Show Accessibility Help
Shift + F10 Shift + Fn + F10 Show Editor Context Menu
Ctrl + K Ctrl + I Cmd + K Cmd + I Show Hover
Shift + Alt + Left Shift + Ctrl + Cmd + Left Shrink Selection
Shift + Alt + A Shift + Option + A Toggle Block Comment
Ctrl + K Ctrl + L Cmd + K Cmd + L Toggle Fold
Ctrl + / Cmd + / Toggle Line Comment
Ctrl + M Shift + Ctrl + M Toggle Tab Key Moves Focus
- Shift + Ctrl + T Transpose Letters
Ctrl + Space Ctrl + Space Trigger Suggest
Ctrl + K Ctrl + X Cmd + K Cmd + X Trim Trailing Whitespace
Ctrl + Shift + ] Option + Cmd + ] Unfold
Ctrl + K Ctrl + J Cmd + K Cmd + J Unfold All
Ctrl + K Ctrl + 9 Cmd + K Cmd + 9 Unfold All regions
Ctrl + K Ctrl + ] Cmd + K Cmd + ] Unfold Recursively

Support for Multilingual Engine

Database Actions provides support for Multilingual Engine (MLE) by enabling you to run JavaScript code in the worksheet.

Prerequisites

For the availability of MLE features in Database Actions, you need the:

  • DBMS_MLE package in Oracle Database Release 21c and later versions. For more information, see DBMS_MLE in Oracle Database PL/SQL Packages and Types Reference.

  • EXECUTE DYNAMIC MLE and EXECUTE ON JAVASCRIPT privileges assigned to you.

You can work with JavaScript code in the worksheet in the following ways:

  • Create a JavaScript worksheet
  • Execute JavaScript code in a standard worksheet
  • Execute JavaScript code as a PL/SQL block

Create a JavaScript Worksheet

You can open the worksheet in JavaScript mode. You will also see the toolbar icons and output tabs change to reflect the JavaScript mode.

To create and save a JavaScript worksheet:

  1. In the toolbar, expand the New File icon and select JavaScript.
  2. When you enter code in the worksheet, the JavaScript code is automatically highlighted.
  3. Execute the JavaScript code in the worksheet using Run Script.
  4. Click Save.

    In the Files pane, (JS) is added to the JavaScript file name. This enables you to quickly identify the JavaScript file.

Execute JavaScript code in a standard worksheet

In a standard worksheet (when the worksheet is not in JavaScript mode):

  1. Select the JavaScript code to execute.
  2. In the worksheet toolbar, expand the Run Script icon and select Run as JavaScript.

    Note:

    Selecting Run as SQL script results in an error.

Execute JavaScript code as a PL/SQL block

You can use a PL/SQL code block to execute JavaScript code.

From the worksheet toolbar, expand the Run Script icon and select Run as SQL script (F5).