Version 1: Last Modified January 26, 2007 Oracle Tutorial 4: Using SQL*Plus SQL*Plus is Oracle database line of products’ default interface. It is lightweight and reliable. Even though it is not as user-friendly compared to Microsoft Access-like development and administration interface. SQL*Plus does have its advantages. In this tutorial, we are learning the following SQL*Plus features. 1. Obtaining Oracle Online Help regarding SQL*Plus error messages. 2. 3. Learn the three variations of SQL*Plus and Basic SQL*Plus Commands. Stop and Start Oracle Processes (to performance of your computer) Part 1: Getting Online Help Oracles DBMS and many other sophisticated applications are difficult to learn because of its complexity. To start untangle these complexities, you have to nurture your problem solving skills in the technology world. The first thing to learn is to get the most basic help information from the product vendors. Yes, of course. You can always GOOGLE to find help. However, hints and tricks found in discussion forum or search results may not be 100% accurate. Using vendor’s web resource is probably the most reliable method. The error message generated by SQL*Plus are usually self-explanatory. However, it can still be confusion, especially for beginner. If you have encounter error messages that you cannot understand, please visit the following web site. Bookmark this web site for future reference. http://ora-code.com/ Part 2: Learn the Different “Faces” of SQL*Plus We have learned that SQL is the language use d to communicate with any relational DBMS, including Oracle, DB2, and SQL server. What you should also know is that there are many methods of sending SQL statements to DBMS. SQL standard (SQL99) calls these methods “binding styles.” There are four distinct methods of executing SQL statements: Direct Execution, Module Binding, Embedded SQL and call-level interface. DO IT YOURSELF: If you are interested, please search on the web about SQL99 1of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 standard and how it defines different binding styles. Please post your finding to the Oracle discussion forum. Using a client application such as SQL*Plus or using Microsoft Access-like interface are the direct execution method. In this course, we use SQL*Plus as our client application. You can issue both SQL statements and SQL*Plus commands. Please notice that these two sets of statements and command are different. SQL*Plus commands are Oracle specific command. These commands may or may not work in other applications. However, the SQL statements are universally accepted regardless of database vendors. Here, we will try a few basic SQL*Plus commands. SQL*Plus comes in three different Variations: Command-Line SQL*Plus, SQL*Plus for Windows, and iSQL*Plus (Web-Based). In previous tutorial, you have used command-line SQL*Plus when you login to UIS Oracle server through telnet sessions. You have also used SQL*Plus to run the queries in chapter 2. Here, we want to focus on the editorial capability of SQL*Plus for Windows and Spend a little bit time using the iSQL*Plus. In the future, you can use either one of them depending on your preference. SQL*Plus for Windows First, start the SQL*Plus and login to your UIS account. Remember to establish VPN connection before doing so. Also, you have to make sure all the tables required for Week 2 assignments have been created on your UIS Oracle account. If you have not done so, please follow Tutorial 3 and Week 2 assignment to complete this task. Then, type “?” at the SQL prompt (Figure 1). This command is an SQL*Plus command that is not part of SQL. It is the same meaning as HELP. You can use this command to find the most basic explanation for both SQL and SQL*Plus commands. If you continue by typing “? INDEX”, You will get a result similar to Figure 2. Figure 2 show a list of SQL*Plus commands for used with SQL*Plus. In “Uploading” data tutorial, you have already use the “@” operator. Now, you can find out what it means by typing “? @.” (Figure 3) 2of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Figure 1 Oracle SQL*Plus Help Figure 2 A List of Help Topic The true meaning of the @ sign is not “uploading” file. Instead, it is command the SQL*Plus to run an SQL script file.This script file is usually saved under a local directory. However, it is also fine to enter a URL for this command. Nonetheless, the iSQL*Plus only accept the URL form. Now, type “? START.” You will find out that the Start command perform the same job as the “@” operator. Now, type “DESCRIBE WAREHOUSE ”. You will see the result is similar to Figure 4. 3of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Figure 3 Help on @ Figure 4 Warehouse Table Structure DO IT YOURSELF: DESCRIBE is another SQL*Plus command, you can now find it out yourself what it means. Finding out the column definition for the Warehouse table is to insert a new record into the warehouse table for demonstration. We can now try to edit a small SQL script and execute this script from your local directory. The SQL script has to be a plain text document. To be safe, this tutorial use NOTEPAD to perform this job. Start the NOTEPAD and type the two lines shown in Figure 5 and save the file with a name called test.sql. Please do change Professor Wang’s name to your own name. I suggest that you save this file to a short simple directory on your compute r so we can avoid typing a long directory name. Here, I save it to c:\temp \. 4of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Figure 5 Then, enter the command show in Figure 6. You should get the result of record saved in the warehouse table. Your result may have more rows com pared to Figure 6. Figure 6 List Warehouse Table with new entries Capture this screenshot as an evidence of going through the tutorial. Figure 7 Error message created by long a query 5of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 DO IT YOURSELF: To clear SQL*Plus Screen, you can type “CLEAR SCREEN” at the SQL prompt. DO IT YOURSELF: Use the SQL*Plus to find out how to perform SPOOL. An external SQL*Plus tutorial (on the Web from CUNY) is also available on the Blackboard Web site under external link page. Next, let us try the editing capability in SQL*Plus. Figure 7 show a complicate query that is incorrect. This query is taken from your textbook, page 57. I believe that when you are practicing queries in chapter 2, you probably feel frustrated by typing and retyping the SQL command into SQL*Plus. It would be more convenient to use a text editor to edit and paste the SQL command. This task can be done by invokes an editor. The default editor is Notepad. The previous command that you entered into SQL*Plus will be copied into the editor (Figure 8 and Figure 9). Now, you can use the copy and paste function by press Ctrl-C (copy) and Ctrl-V (paste) back and forth until you fix the errors. You can also save the file for future use. Figure 8 Invoke Notepad as editor 6of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Figure 9 Edit query in Notepad Figure 10 iSQL*Plus Login Screen Use iSQL*Plus 7of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 iSQL*Plus is a web verson of SQL*Plus. To start iSQL*Plus, you have to start your browser first. Both FireFox and Internet Explorer (IE) works fine. This tutorial use IE7 for demonstration purpose. Referring to Tutorial 1 (Installation), the URL for iSQL*Plus is showing up at the end of the installation. You have been asked to capture the image and submit it as part of your week 1 assignment. This URL looks similar to the one in Figure 10. The URL in Figure one is instructor’s office machine at UIS. It has a complete URL. The 5560 is the default communication port for iSQL*Plus. If your machine does not have a domain name (like the one in Figure 10), you may see the following variations of URL for iSQL*Plus, depending on your environment. http://machine_name:5560/isqlplus/ http://127.0.0.1:5560/isqlplus/ http://192.168.0.100:5 560/isqlplus/ http://72.182.45.223:5560/isqlplus/ The first line shows an URL using your machine name. You can find this name from the Control Panel > System (Computer Name Tab) if you use Microsoft Windows machine. This is typical if you have setup a W orkgroup for your home network. The second line shows an URL if you have installed a Microsoft Loopback adaptor as provided as an option in Week 1 Module. The third line shows a IP address assigned by a typical router. The number “100” may range from 1 to 255. The last line indicate that your machine is probably connected directly to your cable model or DSL line. The IP address depends on the your high speed internet provider. Do try these variations if you can not make your URL work based on what you turned in for Week 1 assignment. You can do pretty much the same thing using either iSQL*Plus or SQL*Plus for Windows. I find the iSQL*Plus is easier for me to copy and paste my SQL codes. Figure 12 shows a simple query executed using iSQL*Plus DO IT YOURSELF: Please try to execute a few queries from chapter 2 to see how iSQL*Plus works. Especially, try to use the “load script” and “save script” functions. They work similar to the “@” or “start” commands but is much more user friendly. 8of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Figure 11 iSQL*Plus Editor Screen Figure 12 Query results and Editing Area are on the same page 9of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Part 3: Stop and Start Oracle Processes (Service) Oracle DBMS is a network DBMS. Every database controlled by Oracle can be made visible to the Network though a set of Oracle services. By default, these services (computer programs) started automatically and will use up memory and computing power. If your system suffers notable performance loss after Installing Oracle, the problem is probably due to these automatically started services. To perform other task when you are not using Oracle, you can manually stop or start these processes when needed. Start and Stop these processes follow a few easy steps. Go to control panel and switch to “Classic View”. You should be able to see the screen similar to Figure 13. Figure 13 Control Panel Classic View Double click (or single click, depending on your Windows setting), the Administrative Tools, you should see the windows like Figure 14. Double click again, you will see Figure 15. Look for services start with “Oracle,” you will find at least 4 services. Now, you can start or stop service as you like for your PC. The recommendation is changing all start/stop optio n as “Manual.” 10of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Figure 14 Administrative Tools Figure 15 Services Running on your PC 11of 12 All Right Reserved by Te-Wei Wang Version 1: Last Modified January 26, 2007 Figure 16. Services can be modified here This is the End of Tutorial 4. 12of 12 All Right Reserved by Te-Wei Wang