Oracle SQL Developer Command Line is a powerful tool for executing SQL scripts, running queries, and debugging connections—all without needing a full IDE. In SQL Developer 18.2, this command-line interface simplifies automation, testing, and troubleshooting, but requires proper setup to avoid common failures. Below is a complete walkthrough for first-time users.

What You'll Need

  • A computer running Windows, macOS, or Linux with Oracle SQL Developer 18.2 installed (download from Oracle's official site)
  • An Oracle database connection (TNS listener configured if remote access is needed)
  • Basic familiarity with SQL syntax (optional, but helpful)
  • Text editor or IDE (VS Code, Notepad++, etc.) for script preparation

Step-by-Step

  1. Open SQL Developer Command Line
    Launch SQL Developer, then click Tools > SQL Developer Command Line (or press Ctrl+Shift+R if using the command palette). The prompt will appear in a separate window, ready for commands.
  2. Establish a Connection
    The command line connects to the database using a credential file or direct input. Use one of these methods:
    1. For local connections, type: sqlplus / as sysdba (Note: This requires admin privileges and may not work on all systems.)
    2. For connection strings (username/password), use: sqlplus username/password@hostname:port/SID Replace values with your database credentials (e.g., scott/tiger@ora.example.com:1521/ORCL).
    3. For credential files (recommended for security), place a file at ~/.sqldeveloper/sqlplus.conf (Linux/macOS) or %USERPROFILE%\.sqldeveloper\sqlplus.conf (Windows). Example entry: [default] user = scott password = tiger host = ora.example.com port = 1521 service_name = ORCL Run the command line with: sqlplus (without arguments to auto-load).
  3. Execute SQL Commands
    Once connected, enter SQL statements directly. Examples:
    1. Run a simple query: SELECT * FROM employees;
    2. Execute a stored procedure: EXECUTE emp_package.my_procedure('test');
    3. Save a script to a file (e.g., employees.sql): spool employees_results.txt SELECT * FROM employees; spool off
  4. Run Scripts from Files
    Use the sqlplus -s flag to execute scripts line-by-line: sqlplus -s username/password@host:port/SID @path/to/script.sql Example (on Linux/macOS): sqlplus -s scott/tiger@ora.example.com:1521/ORCL @scripts/employees.sql On Windows, use: sqlplus -s scott/tiger@ora.example.com:1521/ORCL scripts\employees.sql
  5. Debugging Interactivity
    Use the dbms_output.put_line function to print dynamic results: BEGIN FOR i IN 1..10 LOOP dbms_output.put_line('Iteration ' || i); END LOOP; END; Enable output with: SET serveroutput ON SIZE 1000000 (Press Ctrl+Shift+Enter in SQL Developer to run a block.)
  6. Exit Safely
    Close the command line window or type: exit or quit to end the session without disconnections.

Common Mistakes

  • Connection failures
    Common causes: wrong credentials, misconfigured TNS listener, or port blocking. Verify with: telnet ora.example.com 1521 (Replace with your database details; should show "Connected." if working.)
  • Permission errors
    Use / as sysdba only on local databases (not remote or production). For remote, use a dedicated schema.
  • The spool command writes results to a file. Ensure the file exists or redirect to a fixed path: spool ./results.txt (Use forward slashes on Linux/macOS, backslashes on Windows.)

Tips

  • Use SET LINESIZE 100 to view long output in one line.
  • Pipe SQL output to other tools: sqlplus @script.sql | grep invalid (Shows only invalid rows in the script.)
  • For large scripts, break them into chunks and run selectively.
  • Use SET HEADING OFF to suppress default column headers.
  • Store credentials securely in ~/.sqldeveloper/sqlplus.conf (not in scripts).

Troubleshooting

If the command line fails to connect or run commands, check these steps in order:

  1. Restart SQL Developer
    Sometimes the UI and CLI get out of sync. Close and reopen the IDE.
  2. Verify database accessibility
    Test the connection manually via command line: sqlplus -v username/password@host:port/SID (Replace with real credentials.)
  3. Check TNS listener status
    On Linux/macOS: tnsping ora.example.com On Windows: tnsping ora.example.com If "TNS: no listener," the listener is down. Restart Oracle services.
  4. Reinstall SQL Developer
    If all else fails, uninstall and reinstall the application.

Note: If you encounter Oracle error 12593, the TNS listener is misconfigured. Verify the listener.ora file on the database server.

Frequently Asked Questions

How do I connect to a remote Oracle database?

Use the full connection string (username/password@hostname:port/SID) or a TNS alias. Example: sqlplus scott/tiger@ora.example.com:1521/ORCL If TNS is configured correctly, it will resolve the hostname to the database.

Can I use SQL Developer Command Line without the full IDE?

Yes, the command line operates independently of SQL Developer's GUI. You can use it directly after installation.

What if my script includes dynamic SQL?

Use the DBMS_SQL package for dynamic queries. Example: DECLARE v_cursor SYS_REFCURSOR; BEGIN OPEN v_cursor FOR EXECUTE IMMEDIATE 'SELECT * FROM dynamic_table'; FOR rec IN v_cursor LOOP DBMS_OUTPUT.PUT_LINE(rec.column_name); END LOOP; END;

How do I handle errors in scripts executed via the command line?

Enable detailed error messages with: SET ERRORSIZE 5000 Then run the script. Errors will appear in the command line output.

Can I export results from the command line directly to CSV?

No direct export exists, but you can use a pipeline: sqlplus @script.sql | while read line; do echo "$line" | awk '{print $1","$2"..."}' > results.csv; done

(paste the SQL into the command line and use a shell script to format it.)

What’s the difference between sqlplus and SQL Developer Command Line?

sqlplus is Oracle’s native command-line tool; SQL Developer Command Line extends it with features like spooling, stored procedures, and easier credential management. Use sqlplus for basic tasks if you lack SQL Developer.

For advanced use, consider integrating SQL Developer Command Line into scripts with Batch files (Windows) or shell (Linux/macOS).