Tài liệu Oracle SQL Jumpstart with Examples- P2 ppt

50 437 1
Tài liệu Oracle SQL Jumpstart with Examples- P2 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

20 1.6 SQL Tools Before you begin the following steps, you will need these two pieces of information about your database:  The database name or network name. If you are running the database on your own computer, this is the name you gave the data- base when it was created. If you are not sure what you named it, go to a command prompt (see step 1 to learn how) and then type this command: lsnrctl status Look for a line that begins like this. The word in quotation marks is your database name. In this example, the database SID name is OLTP. Instance "oltp", status READY, . If you are running from a client computer and using a remote database on the network, you must use the network name defined in your local Oracle Net configuration. The configuration file named TNSNAMES.ORA has all of the network names available to you. The file is located in $ORACLE_HOME/network/admin directory. Here is an example of the text found in the TNSNAMES.ORA file for the OLTP network name: OLTP = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 1300server) (PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oltp))) Chap1.fm Page 20 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 1.6 SQL Tools 21 Chapter 1  The password for the users named SYS and SYSTEM. The Oracle Database Configuration Assistant in Oracle Database 10g allows set- ting of SYS and SYSTEM passwords to the same value. If you are running a database on your own computer or on a database server, you can reach the database directly by omitting the database name. When you omit the name, Oracle uses the bequeth protocol and the cur- rent $ORACLE_SID variable setting to access the database. In Windows the $ORACLE_SID variable is set in the registry, and on UNIX or Linux in a user or root profile. Figure 1.11 shows a Win2K registry location. When you use the database name, Oracle uses the transmission control protocol (TCP). Follow these steps to start up SQL*Plus Command Line and run an SQL command: Note: The steps here, and throughout the book, use the sample tables and data created especially for this book. Appendix A contains instructions for locating and installing all of the sample tables. 1. Go to a command-line prompt on your computer. If you are using Windows, click on Start/Programs/Accessories/Command Prompt. A window appears with a blinking cursor. This is your Figure 1.11 Win2K Registry ORACLE_SID Variable. Chap1.fm Page 21 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 22 1.6 SQL Tools command prompt. If you are using UNIX, you may be at the command prompt when you log in. It looks like a dollar sign ($). If you are not already at the UNIX command prompt, select Ter- minal Window from your Utilities menu or execute an operating system shell. 2. Type the following command, replacing pwd with the password for the SYSTEM user and replacing name with your appropriate network name, and press Enter. sqlplus system/ pwd @ name 3. You will see status information about SQL*Plus and the database and a message stating you are connected. Then your display’s prompt changes to “SQL>”, indicating that you are now in SQL*Plus. Figure 1.12 shows an example of the command prompt window after starting up SQL*Plus. 4. Type the following SQL*Plus commands, and press Enter after each line. These set up the column width displayed for the query that follows. (More on SQL*Plus commands in Chapter 8.) COL PRODUCT FORMAT A35 COL VERSION FORMAT A15 COL STATUS FORMAT A15 5. Type the following query and press Enter: Figure 1.12 SQL*Plus Command Line in Windows 2000. Chap1.fm Page 22 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 1.6 SQL Tools 23 Chapter 1 SELECT * FROM PRODUCT_COMPONENT_VERSION; The asterisk represents all of the columns. Thus all columns are displayed in this query. Figure 1.13 shows the results. The actual data may be different, depending on the shape of your Oracle Database 10g installation. 6. Exit SQL*Plus by typing EXIT and pressing Enter. This returns you to your command prompt. 7. Exit from the command prompt by typing EXIT and pressing Enter. One of the disadvantages of using the command-line mode of SQL*Plus is the inability to use the mouse to correct your typing. You must erase using the backspace key. Table 1.1 shows the editing commands you can use. An advantage of the command-line mode is the ability to add parame- ters to the sqlplus command. For example, you can run a script immedi- ately upon startup, or start SQL*Plus without logging into any database instance (this is useful for issuing SQL commands for starting and stopping the database). SQL*Plus does have a line editor built into it that you can use instead of starting up an editor. Figure 1.13 SQL*Plus SQL Commands Return Instant Results. Chap1.fm Page 23 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 24 1.6 SQL Tools Next, you will look at the Windows-like SQL*Plus tool. 1.6.2 SQL*Plus in Windows Mode This version of SQL*Plus gives you a Windows-like interface with a few environmental options. However, it still requires you to type a single line at a time. To try out SQL*Plus in Windows mode, follow these steps: 1. If you are using a Windows operating system, start the tool by clicking Start/Programs/Oracle – Orahome10/Application Devel- opment/SQL*Plus. If you are using another operating system, go to a command-line prompt, type sqlplusw, and press Enter. You will see a Log On window appear. You must log on with valid credentials now. 2. Type SYSTEM in the User Name box, the current password for SYSTEM in the Password box, and your database name in the Host String box. Figure 1.14 shows the Log On window with the information filled in. Notice that the password appears as a line of asterisks. This is to keep your password private. 3. Click OK to log in. The SQL*Plus window appears. Just like the command-line version, you see status information and get Table 1.1 SQL*Plus Line Editing Commands. Command Description c/old/new Change old to new characters in current line. l or list List the SQL in the buffer. l n Go to line n in the SQL buffer. del n or del * or del n m Delete line n in the SQL buffer, or delete the current line (*) or delete lines n through m. a text or append text Add text to the end of the current line. i or input or i text or input text Insert a new line after the current line. Add text to the line, if text is specified. Chap1.fm Page 24 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 1.6 SQL Tools 25 Chapter 1 an SQL> prompt telling you that SQL*Plus is ready to accept commands. 4. Type the following command and press Enter. This is an SQL*Plus command that tells the database to list the structure of the table or view that you name. A view is a query stored with a name in the database. It acts like a table but does not store any data. (Chapter 19 covers views in detail). DESC DBA_USERS 5. The screen shows the names and datatypes of all the columns in this view. This is very useful when you are about to write an SQL command and you need a quick reminder of the exact column names in a table. Now type this query and press Enter after each line. Notice that the prompt changed from “SQL>” to “2” on the second line. This indicates that SQL*Plus knows you have started a command and you are continuing it on the next line. The semi- colon at the end of the second line signals to SQL*Plus that the command is complete and should be immediately executed. SELECT USERNAME, ACCOUNT_STATUS, CREATED FROM DBA_USERS; 6. The results scroll by, and you can use the scroll bar on the right side of the window to move up or down and view the results. Fig- ure 1.15 shows the results from the query. The column headings Figure 1.14 Log into Your Database as a Valid User. Chap1.fm Page 25 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 26 1.6 SQL Tools and report feedback are standard parts of every mode of SQL*Plus; however, the scroll bar and the menu are features of the Windows mode and not of the command-line mode. Some operating systems will allow configuration changes to allow addi- tion of scroll bars to command-line windows. 7. Click on Edit in the top menu and invoke the editor. A window appears with an editing program and the text of the query you wrote ready for editing. In Windows, the default editor is Note- pad. In UNIX, Linux, and other operating systems, the default editor can be configured in a user profile. 8. The editor can be used to change the command you created while working in SQL*Plus. You can retrieve files with SQL commands in them using the File/Open command on the menu. Selecting the File/Run command from the menu will execute the most recent SQL command. Modify the query by removing the CRE- ATED column from the query. 9. Save the file and exit the editor. The modified query now appears on the screen, ready to run if you choose. Figure 1.16 shows what your SQL*Plus screen should look like now. 10. Before running the command, select File/Spool/Spool File from the menu. A window opens in which you can select the file name and location. This file will contain everything you type and SQL*Plus returns from the moment you return to SQL*Plus Figure 1.15 SQL*Plus in Windows Mode Has a Scroll Bar and Menu. Chap1.fm Page 26 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 1.6 SQL Tools 27 Chapter 1 until you turn it off, or until you exit SQL*Plus. This is a handy way to record your work. In addition, in Chapter 8, you will find out how to write reports using this spooling technique. Navigate to a directory of your choosing, such as C:\TEMP in Windows, and then type “testing” as the file name and click Save. The file will automatically receive a suffix of “.LST” on Windows and of “.lis” on UNIX and other operating systems. 11. Type / (a forward slash) to run the query. The forward slash and the semi-colon both tell SQL*Plus to execute a command. The forward slash must be used alone on a line by itself, whereas the semi-colon is used at the end of a line of code. The semi-colon terminates and submits a single-line SQL command to the data- base. The forward slash does the same and additionally compiles and executes blocked sections of PL/SQL code. 12. The results scroll into the window as before. 13. Type the letter L and press Enter. This is the LIST command of SQL*Plus. It displays whatever SQL command is currently in the SQL*Plus buffer. 14. Select File/Spool/Spool off to end the spooling of data to the file. This closes the file that has been receiving data from the SQL*Plus session. Your spool file will be empty until this com- mand is executed or you exit SQL*Plus. Figure 1.16 Invoking (Opening) the Editor. Chap1.fm Page 27 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 28 1.6 SQL Tools 15. Exit SQL*Plus by typing EXIT and pressing Enter or by clicking the X at the top right corner of the window. 16. Navigate through Windows Explorer to find the TESTING.LST file that was spooled in the location you chose. If you are using UNIX, use the cd command or your File Directory window to find the testing.lst file. Open the file with your editor and view the results. You should see the forward slash (the first thing you typed after turning on spooling), the query results, the “L” com- mand, and the query in this file. Spooling is useful for saving queries you develop in SQL*Plus. In addition, with a few extra commands, you can create a report (with headings, titles, summaries, and so on) from SQL queries and spool the report to a file ready for printing. 17. Close the file. Note: If you make a mistake and press Enter before fixing it, you sometimes get a line number prompt instead of an SQL prompt. This means SQL*Plus has interpreted your line as the beginning of a command and is expecting you to complete the command before executing. To get out of this continuing line mode, type a period (.) alone on a line and press Enter. You will be returned to the SQL prompt so you can begin again. Another form of the SQL*Plus tool can be found within Oracle Enter- prise Manager. 1.6.3 SQL*Plus Worksheet The Oracle Enterprise Manager (OEM) is a great set of tools for the data- base administrator (DBA). The OEM Console gives you a bird’s-eye view of your database, or many databases if you have access to more than one. The SQL*Plus Worksheet is a standard part of the OEM suite that is installed when you install Oracle Database 10g (Enterprise, Standard, or Personal Editions). To run the worksheet by itself, without going through the OEM Con- sole, follow these instructions: Chap1.fm Page 28 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 1.6 SQL Tools 29 Chapter 1 1. Start SQL*Plus Worksheet from Windows by clicking Start/Pro- grams/Oracle – Orahome10/Application Development/SQL*Plus Worksheet. If you are using UNIX, Linux, or other platforms, go to a command prompt and type: oemapp worksheet 2. A login window appears. The window title is “Oracle Enterprise Manager Login” because the same login window appears for the OEM Console and other OEM tools. Select the “Connect directly to the database” button. Note: The Management Server is out of the scope of this book. Type SYSTEM in the User Name box, the current password for SYSTEM in the Password box, and your database name in the Service Name box. Leave the Connect As box defaulting to “Nor- mal.” Figure 1.17 shows the completed login window; click OK to log into SQL*Plus Worksheet. 3. The SQL*Plus Worksheet window appears. The top windowpane is your area for typing SQL commands. The lower pane displays the results. Click Enter to clear the window. 4. Type the following query in the top pane: SELECT FILE_NAME, BYTES FROM DBA_DATA_FILES; Figure 1.17 Log into SQL*Plus Worksheet. Chap1.fm Page 29 Thursday, July 29, 2004 9:59 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... Features of Oracle SQL In this chapter: What are the new features of Oracle SQL in Oracle Database 10g? What were the new features of Oracle SQL in Oracle Database 9i? What PL /SQL improvements are there? How is XML development better supported? What’s new in Oracle SQL utilities? This chapter takes a bird’s-eye view of Oracle SQL changes in both Oracle Database 10g and Oracle Database 9i Without further... PL /SQL programming is covered in Chapter 24 Everything possible in Oracle SQL with respect to SQL coding can now be coded and executed from within PL /SQL PL /SQL is now fully syntactically equivalent with Oracle SQL In other words, all Oracle SQL commands can be coded into PL /SQL scripts The PL /SQL compiler is better optimized including bulk binding and native compilation Native compilation stores PL /SQL. .. Oracle Database 9i Without further ado, let’s get started with Oracle Database 10g 2.1 New Features in Oracle Database 10g Oracle Database 10g contains the following SQL and PL /SQL features 2.1.1 Oracle SQL Improvements in Oracle Database 10g Oracle documentation states that case sensitivity is no longer required for filtering and sorting in SQL statements Proving this point is a tuning exercise and... for SQL in both Oracle Database 10g and Oracle Database 9i 1.8 Endnotes 1 www.oracledbaexpert.com /oracle/ secure/Normalization.doc 2 Oracle Performance Tuning for 9i and 10g (ISBN: 1-555-58305-9) 3 My version of the Normalization is a highly simplified version I have twisted Normal Forms deliberately 4 http://www.oracledbaexpert.com /oracle/ secure/ Denormalization.doc 5 http://www.oracledbaexpert.com /oracle/ secure/... learning SQL and SQL* Plus commands Feel free to use the other tools if you prefer, although screenshots, when they are used, will display SQL* Plus Worksheet window in most cases 1.6.4 iSQL*Plus The Web server, called Oracle HTTP Server, can be installed with Oracle Database 10g The HTTP Server is a miniature application server set up to run the Web-based tools and programming aids that come with Oracle. .. administration than to Oracle SQL specifically: Multiple temporary tablespaces using tablespace groups can now be set for a user (schema) within the CREATE USER command syntax Nested table and VARRAY types can now be changed Now let’s go backward in time and make a quick synopsis of Oracle SQL and PL /SQL features introduced in Oracle Database 9i, perhaps putting some of the changes for Oracle Database 10g... changes for Oracle Database 10g into perspective 2.2 New Features in Oracle Database 9i Oracle Database 9i (Release 1 or Release 2) contained the following new features for SQL and PL /SQL Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 2.2 New Features in Oracle Database 9i 2.2.1 47 Oracle SQL Improvements in Oracle Database 9i A new data warehousing command called MERGE New... synopsis of XML functionality Using XML in Oracle SQL is covered in detail in Chapter 17 2.1.4 Some Utility Improvements in Oracle Database 10g SQL* Plus: The SPOOL [CREATE | REPLACE | APPEND] options enhance the SPOOL command in SQL* Plus Chapter 2 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 46 2.2 New Features in Oracle Database 9i SET SQLPROMPT can be set to values such as... login script in the $ORACLE_ HOME/sqlplus/admin directory GLOGIN .SQL is now executed for every database connection, not only on opening the SQL* Plus utility Contents of the recycle bin can be viewed DBMS_OUTPUT functionality is more easily provided iSQL*Plus now allows prompts for input values Now let’s look at changes made to various database objects, those directly related to Oracle SQL, not database... functions can help with setting up flashback queries The packages UTL_COMPRESS and UTL_MAIL are new The UTL_COMPRESS package allows data compression The UTL_MAIL package simplifies e-mail from within PL /SQL, where underlying protocol detail is not required 2.1.2.1 Java Improvements in Oracle Database 10g The Oracle Database kernel JVM is improved in Oracle Database 10g for compliance with the latest version . Features of Oracle SQL In this chapter:  What are the new features of Oracle SQL in Oracle Database 10 g ?  What were the new features of Oracle SQL in Oracle. in Oracle Database 10 g Oracle Database 10 g contains the following SQL and PL /SQL features. 2.1.1 Oracle SQL Improvements in Oracle Database 10g  Oracle

Ngày đăng: 24/12/2013, 12:17

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan