How to Run SQL Scripts in SQL Developer
Execute .sql files, run multiple queries at once, and automate your database tasks. This guide covers everything from basic script execution to advanced options.
Run Statement vs Run Script
Know the difference
Run Statement (Ctrl+Enter)
Executes only the single statement where your cursor is. Results appear in a grid. Best for testing individual queries.
Use when: Testing a SELECT, running one INSERT/UPDATE
Run Script (F5)
Executes all statements in the worksheet from top to bottom. Output appears in Script Output panel. Best for running .sql files.
Use when: Running migrations, creating tables, bulk operations
How to Run a SQL Script
Three ways to execute your scripts
Open and Run
File → Open (or Ctrl+O)
Select your .sql file
Choose a database connection
Press F5 to run
Drag and Drop
Drag your .sql file directly into SQL Developer's editor area. It opens in a new tab. Select connection and press F5.
Use @ Command
In any worksheet, type:
@C:\path\to\script.sql
Then press F5. This also works for running scripts from within other scripts.
Understanding Script Output
Where to see results and errors
When you run a script with F5, output appears in the Script Output panel at the bottom:
- SELECT results: Displayed as text tables
- DML statements: Shows "X rows inserted/updated/deleted"
- DDL statements: Shows "Table created", "Index created", etc.
- Errors: Shows line number and error message
Tip: If you don't see Script Output, go to View → Script Output or press F8.
Advanced Script Options
Control how scripts execute
Run with Variables
Use &variable_name in your script. SQL Developer prompts for values when you run it.
Example: SELECT * FROM users WHERE id = &user_id;
Spool Output to File
Save script output to a file:
SPOOL C:\output.txt
SELECT * FROM users;
SPOOL OFF
Exit on Error
Add WHENEVER SQLERROR EXIT at the start of your script to stop execution
if any statement fails. Useful for deployment scripts.
Common Script Issues
Troubleshooting script execution
"No connection" error
You need to select a database connection before running. Look at the dropdown in the toolbar above the editor - select your connection there.
Script stops at first error
By default, SQL Developer continues on error. If yours stops, check your script for
WHENEVER SQLERROR EXIT. Remove it to continue past errors.
Nothing happens when I press F5
Make sure focus is on the SQL editor (click in the editor first). Also check that your script has proper statement terminators (semicolons).
Encoding issues (strange characters)
Your .sql file might be saved in a different encoding. Try File → Open With Encoding and select UTF-8 or the correct encoding for your file.
Need SQL Developer?
Download free for Windows. Run scripts on Oracle, MySQL, PostgreSQL, and more.