In this second part of a seven-part article series, you'll learn how to use SQL*Plus, a command line tool, to work with the Oracle SQL database. While newer tools are easier to use, this one has been around for a long time, and many developers still use it. 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 use SQL Plus
Figure 2-3 shows how to use a command-line tool known as SQL*Plus to work with the database. The SQL*Plus tool has been around since the earliest days of the Oracle database, and many Oracle developers still use it. However, the newer SQL Developer tool described later in this chapter is easier to learn and use than the SQL*Plus tool. That’s why this chapter and the rest of this book shows how to work with the SQL Developer tool.
Still, there may be times when it makes sense to use SQL*Plus. If, for example, you are working on a computer that has SQL*Plus installed but doesn’t have SQL Developer installed, you may need to use SQL*Plus to run some SQL statements. Or, you may need to develop a batch file that uses SQL*Plus to run one or more SQL scripts. Figure A-5 of appendix A, for example, shows how to run a batch file that starts SQL*Plus and uses it to run four SQL scripts. In that case, of course, it makes sense to use SQL*Plus.
If you need to start SQL*Plus, you can do that by selecting the Run command from the Start menu, entering “sqlplus”, and selecting the OK button. Then, you can connect to the database as a user by entering the username and password. In this figure, for example, I started by connecting as the AP user.
Once you’re connected to the database, you can run SQL statements. To do that, you type the SQL statement followed by a semicolon and press the Enter key. Then, if the statement selects data, SQL*Plus will display the data. In this figure, for example, I entered a SQL statement that displays the vendor_name for the vendor with an id of 11.
At any time, you can connect to the database as a different user by entering the CONNECT command. When you enter this command, SQL*Plus prompts you for a username and password. In this figure, for example, I entered the CONNECT command to connect as the OM user.
The SQL*Plus tool
SQL*Plus is a command-line tool that’s installed with the Oracle Database. You can use it to work with an Oracle Database.
To start SQL*Plus, select the Run command from the Start menu, enter “sqlplus”, and select the OK button.
To connect to a database, enter the username and password. If necessary, you can enter the CONNECT command to have SQL*Plus prompt you for a username and password.
To run a SQL statement, type it, type a semicolon, and press the Enter key.
For most tasks, it’s easier to use the SQL Developer tool that’s described later in this chapter.
--------------------------------------------Figure 2-3 How to use SQL*Plus