Search notes:

Oracle SQL Developer

Main functionality

SQL Developer has four core areas where it aims to help the user
The SQL Worksheet is the place where SQL, PL/SQL and SQL*Plus statements can be entered and executed.

Installing

An Oracle account is required to download and/or install SQL Developer.
The downloaded zip file does not contain an installer. Thus, it can be extracted to the desired location.
It is possible to install SQL Developer with Chocolatey. The Oracle account name and password need to be passed with the -params argument. In order to remember name and password for future upgrades, … feature enable -n=useRememberedArgumentsForUpgrade might be executed first:
choco feature  enable -n=useRememberedArgumentsForUpgrades
choco install -y oracle-sql-developer --params "/Username:whoAmI /Password:andWhatIsMyPassword"
Strangely, when installing SQL developer with chocolatey, the executable was found under C:\ProgramData\chocolatey\bin\sqldeveloper.exe. Not sure if this is expected?

No Oracle Home required

SQL Developer connects to a database through the JDBC thin driver. Thus, no Oracle Home is required.
In fact, because SQL Developer uses JDBC thin driver, it is also possible to connect to MySQL and SQL Server from SQL Developer.

Command line

The functionality of SQL Developer is also available on the command line through SQLcl.

Startup arguments

--verbose Show JNI options and verbose progress of launcher (this option deprecates -verbose
-client Use Client as the Java VM
-server Use Hotspot Server as the Java VM
--<directive>=<value> Override a directive from the configuration file
-J<flag> Pass <flag> directory to the runtime system
-conf[igure] <file.conf> Use the specified configuration file
-multi Start a new instance
-migrate Migrate user settings from a previous installation

Code templates

German: »Codevorlagen«
A code template is textual abbreviation for a predefined text snippet (the template). This abreviation is epxanded with ctrl+space.
Code templates can be entered under the menu Tools -> Preferences -> Database -> SQL Editor Code Templates.
Apparently, these code templates are stored (in Windows) under "%appdata%\SQL Developer\CodeTemplate.xml".

Some keyboard shortcuts

ctrl+enter executes the (one) statement under or «behind» the cursor.
F5 on the other hand runs all statements in the worksheet.
ctrl+space expands column names
shift+alt+F8 enters splitter moving mode. When in this mode, home shows the entire SQL-panel and hides the query output, end does the opposite, and the up/down arrows move the splitter between these panes.
alt+pageDown / alt+pageUp cycles through tabs
ctrl+up/down arrow replaces the content of the SQL Worksheet with SQL statements from the SQL history.
ctrl+shift+n creates an unshared (that is: dedicated) worksheet.
ctrl+shift+enter is supposed to show only the editor (but does not work on my installation)
ctrl+F7 Format text of SQL statement. See also Tools -> Preferences -> Code Editor -> Format -> Advanced Format
Keyboard shortcuts can be configured under Tools -> Preferences -> Shortcut Keys and seem to be stored under the user information directory in the file SystemV.W.X.Y.Z/o.ide.x.x.x.x.x.x/settings.xml.

Configuring SQL Developer

Specify startup SQL script

It is possible to have SQL Developer run an SQL script when it is started up.
The location of the startup script is configured in the menu under Tools -> Preferences -> Database: Filename for connection startup script.

Enabling dbms_output

Apparently, SQL Developer does not print the output of dbms_output by default. It can be turned on as follows:
  • Menu View -> Dbms Output (german: Ansicht -> DBMS-Ausgabe).
  • This opens »dbms_output panel«.
  • Click green plus sign (or ctrl+n).
  • Optionally change buffer size (to »unlimited«, german: »unbegrenzt«).

Enabling dbms_output by default

It's possible to enble dbms_output by default by putting the following line in the SQL Developer startup script:
set serveroutput on

Turn auto commit off

Turning off autocommit apparently is an advanced feature:
Preferences -> Database -> Advanced, check box Autocommit

Open unshared worksheet

Use ctrl + shift + n to open an unshared worksheet.
With an unshared worksheet, SQL statements run in the background (the SQL connection is »unshared«), so multiple SQL statements can be run in parallel.
Alternatively, Tools > Preferences > Database > Worksheet and then checking New Worksheet to use unshared connction allows to execute multiple queries at the same time by default.
German: Extras -> Voreinstellungen -> Datenbank -> Arbeitsblatt: Neues Arbeitsblatt mit eigener Verbindung

Specify default location to look for SQL scripts

Tools -> Preferences -> Database -> Worksheet, option Select default path to look for scripts.

Date format for SQL results

The date format (especially important for for select statement results) and other NLS settings can be changed under the menu Tools -> Preferences -> Database -> NLS.

Don't display (null) for null valus

Suppress the explicit writing of (null) in the query result window for null values:
Tools -> Preferences -> Database -> Advanced -> Display Null Value As …
(Apparently, that is an «advanced» setting…)

Run multiple queries in parallel

In order to be able to run multiple queries at the same time, the option New Worksheet to use unshared connection, found under Tools -> Preferences -> Database -> Worksheet, must be enabled.

Only 5,000 rows currently supported in a script results

When executing a script with F5, by default at most 5000 records are printed to the result pane.
This default can be changed under: Tools -> Preferences -> Database -> Worksheet -> Max rows to print in a script.

Encoding

Tools -> Preferences -> Environment: encoding box
German: Extras -> Voreinstellungen -> Umgebung
For exports: Tools -> Preferences -> Database -> Utilities -> Export

Better support to cancel queries

Menu Tools -> Preferences -> Database (tree on the left) -> Advanced -> check Use OCI/Thick driver. (Apparently, Use Oracle-Client needs to be checked, too).

Appearance

The appearance of SQL Developer can be configured under the Environment preferences (Look and Feel).

F5 vs F9

In order to use SQL*Plus features (such as new_value), a script must be executed with F5 rather than F9.

Column order

Apparently, an executed select statement stores the column order. This stored order is not reset after re-creating a table. In order to take the order of the table, a right click on the result's colum headers and choosing delete persisted settings is needed.
That Jeff Smith has more to say on that in Reordering Columns.

Snippets

Menu: View -> Snippets
Then drag the snippets to the SQL worksheet as needed.

Adminstering Oracle REST Data Services

Apparently, it's possible to adminster Oracle REST Data Services with SQL Developer by enabling it with someting like
java -jar ords.war user adminlistener "Listener Administrator"

SQLDEV:GAUGE

with params as (
   select
           0 min_ ,
         100 max_ ,
          33 low_ ,
          67 high_
    from dual
),
val as (
  select  80 ue from dual union all
  select  11 ue from dual union all
  select  42 ud from dual union all
  select  98 ue from dual union all
  select  27 ue from dual
)
select
  'SQLDEV:GAUGE:'  ||
    p.min_  || ':' ||
    p.max_  || ':' ||
    p.low_  || ':' ||
    p.high_ || ':' ||
    val.ue                 "Column name for a wide output."
from
  params p cross join
  val    val;
create table tq84_sqldev_gauge (
  vc varchar2(10),
  num number
);

insert into tq84_sqldev_gauge values('ABC',  66);
insert into tq84_sqldev_gauge values('DEF',  42);
insert into tq84_sqldev_gauge values('GHI',  17);
insert into tq84_sqldev_gauge values('JKL', 100);
insert into tq84_sqldev_gauge values('MNO',  24);

select
  vc,
  'SQLDEV:GAUGE:0:101:33:67:' || num 
from
  tq84_sqldev_gauge
order by
  vc;

User preference settings

In Windows, the user preference settings are stored under %APPDATA%\sqldeveloper\v.w.x.
2020-10-02: it seems that this location has changed to %APPDATA%\SQL Developer\systemV.W.X.Y.Z\o.sqldeveloper and that preferences, such as the NLS date format are stored in the file product-preferences.xml.

Exporting data

Excel

SQL Developer allows to export data to Excel:
  • Right click on any cell in an SQL's result set, then choose export
  • Export wizard opens
  • Choose “excel 2003+ (xlsx)” in “Format” (note, this is above the default of insert, and thus very confusing when trying to find it!)
  • Specify destination file in «File»
  • Click Next
  • Click Finish

Various text based formats

So-called worksheet hints allow to export the result of a select statement to be exported in various text based formats.
For example, using /*insert*/ creates insert statements:
select /*insert*/ col_1, col_2, col_3 from xyz;
Statements using worksheet hints must be executed with F5.
Worksheet hints can be specified anywhere in a statement:
select col_1, col_2, col_3 /*insert*/ from xyz;
The list of worksheet hints is:
/*ansiconsole*/ SQLcl only?
/*csv*/ Comma-separated values (same as /*delimited*/)
/*fixed*/ Fixed-width fields with trailing blanks (When testing it, SQL Developer chose an arbitrary width, thus the result was not fixed-width)
/*html*/ Export as HTML (<table><tr><td>…</td>…</table>)
/*insert*/ Insert statements
/*json*/ JSON
/*loader*/ Pipe (not column) separated. Apparently suitable for SQL*Loader
/*text*/
/*xml*/ XML (similar to HTML)

Playing sound when statement or script is done

On windows, it is possible to use the Speech Object Library to get notified when an SQL statement or SQL script is done executing.
begin
   dbms_lock.sleep(10);
end;
/

host powershell -noProfile -c $sapi = new-object -com sapi.spVoice; $null = $sapi.speak('The script has finished')

TODO

Showing table information

info+ TABLE_NAME

Generate DB Documentation

The «right-click» menu on a Connection has a «Generate DB Doc…» sub-menu which creates some documentation in HTML format.
Although this feature seems very nifty, the documentation is generated with HTML-Frames which don't seem to be supported by Chrome anymore.

Performance improvements

Apparently, performance can be improved by unchecking unneeded features under Tools -> Features.

Executing JavaScript

JavaScript can be executed in the Arbori Editor.
In order to open this Arbori Editor, Code Outline must be opened first, which is possible by using the (right-click) context menu in the SQL Worksheet.
After opening Code Outline, the word Arbori must be typed into the text box at the top of Code Outline. This opens the Arbori Editor.
The following demonstration JavaScript code can then be pasted into the Arbori Editor and executed:
include "std.arbori"

prelude: runOnce -> {

    print("Hello");

    var ConnectionResolver = Java.type('oracle.dbtools.db.ConnectionResolver');
    var connectionList     = ConnectionResolver.getConnectionNames();

    for (var i in connectionList ) {
       print(connectionList[i]);
    }

//  Connection conn = (Connection) DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORA19", "rene", "rene");
    var conn = ConnectionResolver.getConnection('IdeConnections%23Ora19');

    if (conn == null) {
       print("conn == null");
    }
    else {

        var stmt = conn.createStatement();
        var rs = stmt.executeQuery("select object_name, created from user_objects");
        while( rs.next() ) {
            print(rs.getString(1) + ": " + rs.getString(2));
        }
    }
}
In order to see the output in Windows, the Console based executable of SQL Developer must be started, that is <inst-dir>\sqldeveloper\bin\sqldeveloper64.exe, not …sqldeveloper64W.exe or …\sqldeveloper.exe.
Also note that it seems that the current(?) SQL Worksheet needs to contain at least one character.

See also

Connect to SQL Server and MySQL with SQL Developer.
Oracle SQL Developer password decryptor
%APPDATA%\sqldeveloper\v.w.x
sdcli is the SQL Developer Command Line Interface
SQL select hints cause a result set to be returned in a specific format such as JSON, XML or CSV.
The PowerShell module SQL Developer

Index