Using Oracle SQL Developer with SQL Statements and Scripts
(Page 1 of 2 )
In this sixth part of a seven-part series on how to use Oracle SQL Developer and other tools, you will learn how to open and save SQL statements, and how to enter and execute a SQL script. This article is excerpted from chapter two of the book Murach's Oracle SQL and PL/SQL, written by Joel Murach (Murach; ISBN: 1890774502).
How to open and save SQL statements
After you get a SQL statement working the way you want it to work, you may want to save it. Then, you can open it and run it again later or use it as the basis for a new SQL statement. To save a SQL statement, you can use the standard Windows techniques shown in figure 2-11.
To open a file that has been saved, you use the Open command. In this figure, for example, the Open dialog box shows the SQL statements that have been saved for chapter 3. They are saved in the scripts\ch03 directory that is created when you download and install the source code for this book. The screen in this figure shows the tabs for three files that have been opened for that chapter. Note that the names of these files have the sql extension.
After you open two or more SQL worksheets, you can switch between the SQL statements by clicking on the appropriate tab. Or, you can select the SQL statement from the file list that’s available just above the Connections list. Then, you can cut, copy, and paste code from one SQL statement to another.
When you open a saved SQL file, SQL Developer doesn’t set a connection for the SQL statement within the file. As a result, you must specify a connection before you can run the SQL statement by using the Connections list. If you don’t do that, SQL Developer will prompt you to select a connection when you try to run the statement.
To save a new SQL statement in a new file, you use the Save command. To save a modified SQL statement in its original file, you also use the Save command. And to save a modified SQL statement in a new file, you use the Save As command.
To set the default directory that you want to use for saving new SQL statements, you can use the Tools->Preferences command that’s described in this figure. Note, however, that there’s no way to set the default directory for opening files.
For both the Open and Save dialog boxes, you can specify a recently used directory by clicking on its icon. In this figure, for example, the Open dialog box shows that the ch02, ch03, and db_setup directories have all been used recently. As a result, you can easily specify one of these directories by clicking on it.
The Open File dialog box
Description
To open a SQL file, click the Open button in the toolbar, press Ctrl+O, or select the File->Open command. Then, use the Open dialog box to locate and open the SQL file.
To specify a connection for a SQL statement that you open, select a connection from the Connections list (see figure 2-8). Otherwise, when you try to run the statement, SQL Developer will display a dialog box that prompts you to select a connection.
To switch between open statements, select the appropriate tab. Or, click on the drop-down arrow that’s displayed to the right of the SQL Worksheet tabs, and select the file name from the file list.
To cut, copy, and paste code from one SQL statement to another, use the standard Windows techniques.
To save a SQL statement, click the Save button in the toolbar, press Ctrl+S, or select the File->Save command. Then, if necessary, use the Save dialog box to specify a file name for the SQL statement.
To change the default directory for new statements that you want to save, use the Tools->Preferences command. Then, expand the Database node, click on the Worksheet Parameters node, and change the default path for scripts.
To specify a recently used directory in an Open or Save dialog box, click on the icon for the recently used directory.
---------------------------------------Figure 2-11 How to open and save SQL statements