Seneca College Applied Arts & Technology School of computer studies BTD 310 - SQL Database Design Using Oracle Introduction To iSQL*Plus Overview Connecting to iSQL*Plus Entering SQL and PL/SQL Statements Other Options iSQL*Plus Versus Client SQL*Plus Summary Note: Spool is not available in iSqlplus. You need to run your code in sqlplus to make a spool file. How do you make a spool file? Write the following syntax structure in your sql file and call it from sqlplus. spool c:\temp\myspool.lst Write your code here.. Spool off To call your sql file write; @c:\temp\mysql.sql Overview The iSQL*Plus Server is a new feature available in Oracle9i that provides browser-based access to SQL*Plus capabilities. SQL*Plus is a basic software tool that allows Oracle users to enter and execute SQL and PL/SQL commands. Course Technology authors present usage of the SQL*Plus client tool within a number of the Oracle series texts. However, the iSQL*Plus interface has several differences from the client SQL*Plus tool. Therefore, this introduction serves to introduce the browser-based interface and identify some of the execution differences that you may encounter when using iSQL*Plus versus client SQL*Plus. iSQL*Plus is advantageous in academic settings because no client machine setup or installation is required. Users simply need Web browser software and an Internet connection to access the Oracle9i database server. In addition, iSQL*Plus provides a more user-friendly interface. The advantages of iSQL*Plus are Access to the Oracle 9i database from any computer connected to the Internet or intranet Command-line editing capabilities User-friendly interface Access to help files Ability to save the history of a session Unique identification of each iSQL*Plus session so that multiple connections are allowed The architecture is a three-tier model comprised of Client tier 1 o The iSQL*Plus interface is usually a Web browser; only the URL of the Oracle HTTP server is required to connect to Oracle 9i. Middle tier o iSQL*Plus Server o Oracle Net o Oracle HTTP Server Database tier o Oracle9i Connecting to iSQL*Plus 1. Connect to your Internet service via a network or ISP. 2. Enter your Oracle9i HTTP server's URL in the browser address area. This will be in the format: http://your_ machine_name.domain:7777/isqlplus. Note www is not in the URL. The 7777 will be replaced by the port number set to listen for connections upon installation of the iSQL*Plus server. 3. The Login screen will appear as shown in Figure 1. Enter your user name and password. The Connection Identifier can be left blank if you are connecting to the default database. Otherwise, the correct database connection string as included in the server’s tnsnames.ora file will be needed. 4. Click Login. Server URL Enter information into the Username and Password fields, and then click Login Enter database connection string if you're not using the default database Figure 1 iSQL*Plus Login screen 2 Entering SQL and PL/SQL Statements Statements can be entered in different ways, including: Type the statements directly into the Enter statements text area or work area. Copy text from a text editor and paste it into the Enter statements area. Use the Browse and Load Script buttons to load statements from a file. A. Type statements into the work area: 1. Type a statement such as a SELECT directly into the Enter statements area, as shown in Figure 2. Editing is easier than in the client SQL*Plus tool. If a mistake is made, it can be edited right in the Enter statements area using the familiar mechanisms of highlighting, cutting, and pasting and simply clicking where the cursor is needed to add or change text. Type the statement here Execute button runs the contents of the Enter statement area Results from executing the SQL statement; default formatting shows results in an HTML table format Figure 2 iSQL*Plus Work Screen 2. Click the Execute button to execute the statement. Note that the results or error message appear below the Enter statements area. The statement remains available so that modifications can be easily made and executed again. 3. If you desire to maintain a log file of your session including statements executed and the results, cut and paste to a text editor, such as Notepad, or a word processing tool, 3 such as Word. Highlighting HTML table output and copying/pasting into Word pastes the results in a Word table. 4. If you want to save the statement in a script file to rerun at a later time, click the Save Script button. This prompts you for a filename and location in which to save the file. You may want to enter a file extension of .sql to identify the file as an SQL script file. B. Copy/paste statements into the work area: 1. If you prefer to create all your statements in a text file and then test or execute them, copying and pasting from the text editor to the work area can be easily accomplished. The execution and modification of statements are handled in the same manner, as discussed in the previous section. C. Load statements from a file: 1. Click the Browse button located above the Enter statements area, as shown in Figure 3. A Choose file dialog box appears, allowing you to select the file you want to load. This file must be a text file that contains SQL and/or PL/SQL statements. 2. Select the desired file and click Open. The file location and name will now appear in the File or URL text box above the Enter statements area. 3. Click the Load Script button and all the text from the file will now be loaded into the Enter statements area. 4. At this point, you can execute or modify as needed. Note that multiple statements can be entered and executed. 4 Browse for the file located on your local machine and open it The Load Script button loads the text into the Enter statements area Figure 3 Loading script files Other Options (shown in Figure 4) 5 A. Clear Screen: The Clear Screen button removes all statements and results from the screen, leaving the work screen ready for new input and output. B. Cancel: The Cancel button interrupts the script that is executing. New Session allows you to log in as the same user or new user Help page Logout terminates that session History contains previously executed statements Figure 4 Preferences and other settings Work Screen components C. Logout: To end the session, simply click the Logout button located at the top right of the screen. D. New Session: If you need multiple Oracle sessions for testing or completing tasks, click the New Session button and a new browser window will open and present the iSQL*Plus Login screen. 6 E. History: The History screen, as shown in Figure 5, will display previously executed statements from which you can select to load into the Enter statements area. Note that the history list clears when the user ends the session. Blue background indicates this is the active page Previous statements executed, most recent at the top Make selections of statements to load using check boxes Figure 5 Using the History feature Click the Load button after desired statements are selected F. Preferences: Interface options, as shown in Figure 6, allow the user to size the Enter statements area, the location for output, and the number of statements to be stored in history. 7 Figure 6 Interface Options screen The Set system variables area offers a variety of settings that affect the session environment from output line size to turning timing on. We will explore one of these settings later in this guide in the section titled "iSQL*Plus Versus Client SQL*Plus." The Change your password selection provides an easy way to change your Oracle password. G. Help: The Help screen, as shown in Figure 7, contains a wealth of information pertaining to the iSQL*Plus environment and command syntax. Notice the navigation and index buttons located at the top right. The Help screen appears in a new browser window and does not affect the current session window. 8 Navigation and index buttons Figure 7 Help screen iSQL*Plus Versus Client SQL*Plus Two specific differences can cause frustration for those familiar with using the client SQL*Plus tool, but who switch to using the iSQL*Plus tool. This section addresses the differences in using the @ command and output formatting options of line breaks and indenting. A. The @ or START command: The client SQL*Plus tool allows the execution of files located on the client machine by using the @ or START commands. However, using the @ or START command in iSQL*Plus specifies a script by the URL from a Web server. This is fine if you have located script files on the Web server, but much of the time, we desire to run a file located on our computer. To do this in iSQL*Plus, use the load script feature discussed earlier in this guide. B. Text output option: Options can be used in SQL and PL/SQL statements to format output with line breaks or indenting. These options work fine in client SQL*Plus because the output is in text format. However, the default output of iSQL*Plus is in HTML format, which does not 9 recognize the line break or indenting commands. We will look at an example of using the CHR(10) line break option in an SQL command. If you are using any indenting options such as in the dependency tree utility in PL/SQL, the indenting will not be achieved unless the output is set to text format, as we will do in our line break example. Notice the SELECT statement executed in client SQL*Plus, shown in Figure 8, processes the line breaks in the statement. Figure 8 Line break in client SQL*Plus However, if we execute the same statement in iSQL*Plus, as shown in Figure 9, notice that the line breaks are ignored. 10 Figure 9 Line break not operable in iSQL*Plus This can be resolved by modifying the preferences in the iSQL*Plus session to choose a text output format rather than the default HTML format. Select the Preferences button at the top right and then select the Set system variables option to make preference-setting changes. Move down the alphabetical list of settings until you find the Markup HTML area, as shown in Figure 10. Within this area, set the Preformat option to On. Clicking OK and OK saves the setting and returns you to the work screen. 11 Set Preformat to On Figure 10 Setting the Preformat preference Now, if you execute the same SQL statement again, as shown in Figure 11, notice the output is in text format and the line breaks are processed. If you are cutting/pasting your results to a text editor such as Notepad, this setting is preferable because it is already in text format. 12 Figure 11 Line break operable in iSQL*Plus Summary iSQL*Plus provides a more user-friendly environment for entering and executing SQL and PL/SQL statements on an Oracle9i database. In addition, it offers the ease of access and setup by only requiring the user to have Web browser software and an Internet connection. This guide simply introduces the use of the iSQL*Plus interface; for further details, see the SQL*Plus User's Guide and Reference at the OTN Web site. 13