Lesson 3 | Editing and running a query in SQL*Plus |
Objective | Change text by using the in-line editor and run a query. |
Editing, Running Query in SQL*Plus
SQL*Plus contains its own line editor to make quick changes to SQL code.
While too clumsy for editing more than a few lines of SQL or PL/SQL code, it can save time when you are debugging ad-hoc queries or other short SQL commands. The SQL*Plus editor is similar to the UNIX line editor called ed. The following table lists the editing commands available.
SQL*Plus saves the current command in its buffer. You can modify the text in the buffer by using these commands:
Command | Description |
A[PPEND] text | Append text to end of current line. |
C[HANGE] separator old [separator [new [separator]] | Change old to new. Separator can be any symbol that is not a letter or number, such as /. If new is omitted, old is simply deleted. |
DEL [n] | Delete line number n from buffer. If n is omitted, delete the current line. |
I[NPUT] [text] | Insert a new line with text immediately after the current line. If text is omitted, a blank line is inserted and you can type into it. |
L[IST] [n] | List line n of the buffer and make it the current line. If n is omitted, list all lines in the buffer. |
Run SQL*Plus from your desktop client machine
If you want to run SQL*Plus from your desktop client machine, select the SQL Plus program option from the Application Development menu option under the Oracle software menu option. This starts SQL*Plus. (Note that you do not type the * that is in the middle of the official product name, and the asterisk does not appear in the program name, either.) Because Oracle is careful to guard who can access the data it stores, it requires that you enter an ID and password to connect to it. Oracle will display a copyright message and then ask for your username and password.
Log into your database using the account and password you created to hold the sample tables. If you provide a valid username and password,
SQL*Plus will announce that you are connected to Oracle and then will display this prompt:
Read about listing, changing, and running a query in the following simulation.
SQL Plus Editor Commands
The next lesson shows another way to edit your SQL*Plus commands.