Tài liệu Oracle SQL Jumpstart with Examples- P5 docx

50 341 0
Tài liệu Oracle SQL Jumpstart with Examples- P5 docx

Đ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

170 8.4 Using iSQL*Plus cuted within the browser HTML page, both of which are stored on the server running the HTTP server process. Figure 8.27 Your Customized Report Running Web Page. Figure 8.28 The CDREPORT Script Was Run and Displayed. Chap8.fm Page 170 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 8.4 Using iSQL*Plus 171 Chapter 8 This example placed the username, password, and Oracle database net- work name (SID) in the source code. This is not necessarily a good idea in a commercial environment from a security perspective. Anyone can view the source code of an HTML document and retrieve information. It would be better to modify the HTML in your document so that the user is required to enter a username and password. Additionally, secure socket layers (SSL) can be used to encrypt data traveling between a Web browser and the server. 8.4.2 iSQL*Plus versus SQL*Plus The main features of iSQL*Plus are similar to the features of SQL*Plus or SQL*Plus Worksheet:  Enter SQL commands in a box and click the Execute button to dis- play the results. Results can be displayed below the box or in a new browser window.  Adjust environment settings by clicking the Preferences button, using a series of radio buttons and boxes to modify settings such as HEAD- ING, RECSEP, and so on.  Use variables just like SQL*Plus, except you cannot use the ACCEPT or PROMPT commands to prompt for values. iSQL*Plus displays its own prompt. Note: iSQL*Plus allows prompts for input values.  Review and retrieve previous SQL commands by clicking the History button, much like SQL*Plus Worksheet. 8.4.3 Troubleshooting iSQL*Plus If there are problems running iSQL*Plus, configuration settings and other things can be checked on the server.  Check that the port number is the default 7778 value in the file HTTPD.CONF in the $ORACLE_HOME/Apache/Apache/conf directory. Chap8.fm Page 171 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 172 8.4 Using iSQL*Plus  The port number should also be in the SETUPINFO.TXT file in the directory $ORACLE_HOME/Apache/Apache. This file should con- tain entries such as the following: http://<hostname>:7778 http://<hostname>:4443 Note: Replace hostname as appropriate.  The file called ORACLE_APACHE.CONF in the $ORACLE_HOME/Apache/Apache/conf directory must include the file ISQLPLUS.CONF in the ORACLE_HOME/sqlplus/admin directory. The include command should be of the following form. Be sure there are no comments (#) in unexpected places. include "$ORACLE_HOME/sqlplus/admin/isqlplus.conf"  Try stopping and restarting the HTTP Server, especially if you have made any changes to any configuration files. A bug in Oracle 9.2 for Windows 2000 caused errors when starting and stopping the HTTP Server using both the Windows service and the Apache command on the Start menu. A solution to this issue is to set the service to Manual and always start and stop Apache and the HTTP Server with the fol- lowing commands executed in a DOS shell (the command line): C:\oracle\ora92\Apache\Apache\apache -k start C:\oracle\ora92\Apache\Apache\apache - k shutdown 8.4.4 Customizing iSQL*Plus Display Numerous preferences can be changed from the iSQL*Plus interface on the client machine. Additionally, on the server there is an HTML cascading style sheet. 1 This style sheet can be altered to change output appearance. The HTML cascading style sheet is called IPLUS.CSS and is located in the $ORACLE_HOME/sqlplus/admin/iplus directory on the server. Changing the style sheet allows customization of colors and fonts used by iSQL*Plus when it formats output for queries. Using the same simple query used pre- Chap8.fm Page 172 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 8.4 Using iSQL*Plus 173 Chapter 8 viously in Figure 8.26, Figure 8.29 has an altered appearance as a result of changes to the style sheet file on the server. In Figure 8.29, all text color is removed, all background colors apart from that in the headings is removed, and all borders are removed from everything but headings. The style sheet has numerous elements. I changed the following two elements:  The TH or HTML table heading tag or element is changed where highlighted. TH { font : bold 10pt Arial, Helvetica, sans-serif; color : black; background : #f0f0f0; padding : 0px 0px 0px 0px; }  The combination TABLE, TR, TD element is also changed where highlighted. TABLE, TR, TD { font : 10pt Arial, Helvetica, sans-serif; Figure 8.29 Changing the iSQL*Plus Style Sheet on the Server. Chap8.fm Page 173 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 174 8.5 Endnotes color : Black; background : white; border : 1 padding : 0px 0px 0px 0px; margin : 0px 0px 0px 0px; } This is a quick introduction to iSQL*Plus that should help you get started with your own experimentation. Remember to review the help screens provided inside iSQL*Plus for more examples of code and quick reference to SQL syntax. This chapter has covered more detail on SQL*Plus and related tools, in addition to the introductory information provided in Chapter 1. The next chapter moves back into Oracle SQL and looks at functions, namely single- row functions. 8.5 Endnotes 1. www.oracledbaexpert.com/menu/DHTML.html Chap8.fm Page 174 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 175 9 Single-Row Functions In this chapter:  What types of built-in functions are available?  What are single-row functions?  What are the categories of single-row functions?  How do functions work with queries?  What are the options when formatting strings, numbers, and dates?  What are data conversion functions?  How are functions combined? This chapter uses the queries you have worked with in previous chapters and expands the way you can use columns by introducing functions. You will examine the types of functions used for different data types. Finally, you will experiment with combining functions together for more flexibility. A function is a built-in PL/SQL program that always returns a single value. You can use the predefined functions (such as the ones discussed in this chapter) or you can create your own (see Chapter 24). A function always returns a single value, as opposed to a procedure, which is a similar type of program but is able to return more than one value. You can call a function within a query or other SQL command. You have already seen a few functions in previous chapters (e.g., NVL and SYSDATE). Before we examine single-row functions in detail, let’s look at Oracle-provided built- in functions in general. Grouping functions are covered in Chapter 11, reg- ular expression functions in Chapter 14, object reference functions in Chapter 16, and XML functions in Chapter 17. Chap9.fm Page 175 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 176 9.2 Single-Row Functions 9.1 Types of Functions Oracle divides all functions into the following categories:  Single-Row Functions . Functions that operate on a single row at a time. This chapter examines this type of function. For example, the UPPER() function converts characters to uppercase.  Grouping Functions . Chapter 11 covers grouping functions in detail.  Aggregate Functions . Functions that operate on a group of rows at one time and return a single row. For example, the COUNT() function counts the number of rows in a table.  Analytical Functions . Functions that operate on groups of rows and return one or more summary rows. For example, the STD- DEV() OVER() function returns the standard deviation rows based on values in one or more columns.  Object Reference Functions . Functions that manipulate the value in columns with the REF datatype in object tables. For example, the DEREF() function returns the value of an attribute in the referenced object table (see Chapter 16).  User-Defined Functions . Functions that are built by you and per- form whatever data manipulations you program them to do. Exam- ples of user-defined functions are given throughout this book, with syntactical details in Chapter 24. This chapter covers many of the dozens of single-row functions available for your use in queries. 9.2 Single-Row Functions Single-row functions add a great deal of power to queries. Use functions in the SELECT clause to modify the appearance of dates, for example. Add functions to the WHERE clause to help determine which rows to include in query results. Place functions in the ORDER BY clause to fine-tune sorting. Chap9.fm Page 176 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 9.2 Single-Row Functions 177 Chapter 9 Note: Placing functions in WHERE and ORDER BY clauses can be detri- mental to performance. 1 There are so many single-row functions that there is not room to cover them all in this chapter. However, you will gain experience with the com- monly used functions. Other more obscure functions are detailed in Oracle documentation. Single-row functions can be subdivided into the following categories:  Character or String Functions . Functions that require a character value or string as input (see Figure 9.1).  Number Functions . Functions that require a number as input. Most of these return a number. For example, the SIGN function returns -1 if the number is negative, 0 if it is zero, and 1 if it is posi- tive (see Figure 9.2).  Binary Floating-Point Number Functions . These func- tions are new to Oracle Database 10 g and could possibly be viewed as a subset of number functions, except that they operate specifically on binary floating-point numbers (see Figure 9.2).  Datetime Functions . Functions that require a date value as input (see Figure 9.3).  Conversion Functions . Functions that convert one datatype to another. For example, the TO_CHAR function can convert a date or number to a character value (see Figure 9.4).  Miscellaneous Functions . Functions that perform unusual tasks. For example, the DECODE function acts like an IF-THEN-ELSE con- struct or CASE statement (see Figure 9.5). Figures 9.1 through 9.5 show all the different types of single-row func- tions. Functions highlighted and marked with an asterisk ( *INITCAP ) in each figure are discussed in this chapter. Additionally, many functions are referred to in other chapters. Chap9.fm Page 177 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 178 9.2 Single-Row Functions Figure 9.1 Single-Row String Functions. Figure 9.2 Single-Row Number Functions. Figure 9.3 Single-Row Datetime Functions. Chap9.fm Page 178 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 9.2 Single-Row Functions 179 Chapter 9 Figure 9.4 Single-Row Conversion Functions. Figure 9.5 Single-Row Miscellaneous Functions. Chap9.fm Page 179 Thursday, July 29, 2004 10:06 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... with function-based indexes Creating too many indexes can hurt performance as well The best option is not to use functions in the WHERE clause, other than with literal values, if possible Once again, further details on Oracle SQL single-row functions can be found in Oracle documentation both online and in Oracle software documentation Specific reference details of all functions can be found in the SQL. .. Functions 181 LPAD( 'oracle' ,10,'X') = 'XXXXoracle' RPAD( 'oracle' ,10,'X') = 'oracleXXXX' Note: Padding a string is sometimes referred to as filling a string TRIM([[LEADING|TRAILING|BOTH] character FROM] expression), LTRIM(expression, string-set), and RTRIM(expression, string-set) LTRIM and RTRIM will remove from the left and the right of the string, respectively, any characters contained within the string... CONCAT( 'Oracle' ,' Database 10g') = 'Oracle Database 10g' 'Oracle' ||' Database '||'10g' = 'Oracle Database 10g' 'My name is '||FIRST_NAME = 'My name is Jim' LOWER(expression), UPPER(expression), and INITCAP(expression) LOWER converts to lowercase, UPPER to uppercase, and INITCAP to mixed case (first letter of each word in uppercase) INITCAP( 'oracle certified professional') = 'Oracle Certified Professional'... substring within a string (the first character in the string is at position 1) The position and occurrence parameters are optional The position parameter determines a start point to search from, and occurrence indicates which duplicate, if any, of the substring should be matched In the following example, the second occurrence of the string 10g begins at position 19: INSTR( 'oracle 10g oracle 10g oracle. .. string with the replacement string Where the REPLACE function matches any search string within the string, TRANSLATE will match each character between the search and replace strings by the position of characters in both the search and replace strings Phew! In simple terms, REPLACE replaces groups of characters and TRANSLATE translates individual characters REPLACE(' o r a c l e',' ','') = 'oracle' ... chapter experiments with example SELECT statements containing many different types of joins In previous chapters you have explored the SELECT, FROM, WHERE, and ORDER BY clauses Both the American National Standards Institute (ANSI) format JOIN clause and the Oracle proprietary format for joining tables are used in all examples where possible The JOIN clause is the ANSI equivalent of the Oracle proprietary... the ANSI equivalent of the Oracle proprietary join syntax We examine both formats for the following reasons: The Oracle proprietary format has not as yet been deprecated in favor of the ANSI JOIN clause; therefore, it is important that even new DBAs be familiar with its use As a side issue, Oracle Certification exams may test both formats Both formats are useful for explaining how joins behave and how... then the substring value is extracted from the left of the string; otherwise, if the parameter is negative, the value is extracted from the right (end) of the string SUBSTR( 'oracle certified professional', 8,9) = 'certified' SUBSTR( 'oracle certified professional',-12,12) = 'professional' Here is a quick example using some of the string functions mentioned previously Figure 9.6 shows the results The query... calculations These types of functions are rarely used other than in financial or numerically related applications Some of these functions are listed here There are many other Oracle built-in functions to do all sorts of weird and wonderful things (see Oracle documentation) SIN(n), COS(n), and TAN(n) Sine, cosine, and tangent ASIN(n), ACOS(n), and ACOS(n) Arcsine, arccosine, and arctangent (the inverse of sine,... to Oracle Database 10g and could possibly be viewed as a subset of number functions, except that they operate specifically on binary floating-point numbers This section is partially repeated from Chapter 2 TO_BINARY_DOUBLE(expression, format) and TO_BINARY_ FLOAT(expression, format) allow for conversions Essentially, these functions are conversion functions, but they are listed here because they deal with . server. 8.4.2 iSQL*Plus versus SQL* Plus The main features of iSQL*Plus are similar to the features of SQL* Plus or SQL* Plus Worksheet:  Enter SQL commands. The file called ORACLE_ APACHE.CONF in the $ORACLE_ HOME/Apache/Apache/conf directory must include the file ISQLPLUS.CONF in the ORACLE_ HOME/sqlplus/admin directory.

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

Từ khóa liên quan

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

  • Đang cập nhật ...

Tài liệu liên quan