1. Trang chủ
  2. » Công Nghệ Thông Tin

Oracle XSQL- P12 ppt

20 254 0

Đ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

Cấu trúc

  • Oracle. XSQL Combining SQL, Oracle Text,XSLT, and Java to Publish Dynamic Web Content

    • Cover

  • Contents

  • About the Author

  • Chapter 1 Introducing Oracle XSQL

  • Chapter 2 Getting Started with XSQL

  • Chapter 3 Hello, XSQL!

  • Chapter 4 XSQL Architecture

  • Chapter 5 Writing XSQL Pages

  • Chapter 6 XSQL Parameters

  • Chapter 7 Database Modifications with XSQL

  • Chapter 8 Oracle SQL

  • Chapter 9 PL/SQL

  • Chapter 10 Using Oracle Text 253

  • Chapter 11 Retrieving XML

  • Chapter 12 XSLT

  • Chapter 13 XSLT In-Depth

  • Chapter 14 Building XSQL Web Applications

  • Chapter 15 Command Line Utility 443

  • Chapter 16 Web Services with XSQL

  • Chapter 17 XSQL Beyond Web Browsing

  • Chapter 18 Custom Action Handlers

  • Chapter 19 Serializers

  • Appendix A Resources

  • Appendix B Related Standards

  • Index

  • Team DDU

Nội dung

Chr The chr function returns the character associated with the number in the database’s character set. If USING NCHAR_CS is specified, it would use the database’s national character set. SELECT chr(65) SIXTY_FIVE , chr(65 USING NCHAR_CS) SIXTY_FIVE_NATIONAL FROM DUAL Table 8.61 lists the results. Table 8.61 Chr Results SIXTY_FIVE SIXTY_FIVE_NATIONAL AA Concat The concat function is equivalent to the || operator. It merges two strings. SELECT concat(job,concat(‘-’,ename)) AS concat_str FROM emp WHERE deptno=10 Table 8.62 lists the results. Table 8.62 Concat Results CONCAT_STR MANAGER-CLARK PRESIDENT-KING CLERK-MILLER Greatest The greatest function returns the alphanumerically greatest string in its parameter list. Numbers and dates can be intermixed in the parameter list, but dates use the default date mask. It’s best to convert dates to strings first with the to_char function. SELECT greatest(‘MAZE1’,ename,job,dname,’MAZE2’) AS greatest_str FROM emp,dept WHERE emp.deptno=dept.deptno AND emp.deptno=10 200 Chapter 8 Table 8.63 lists the results. Table 8.63 Greatest Result GREATEST_STR MAZE2 PRESIDENT MILLER Initcap The initcap function capitalizes the first letter and lowercases all other letters. SELECT INITCAP(‘mIXeD CaSE’) AS initcap_str FROM DUAL Table 8.64 lists the results. Table 8.64 Initcap Results INITCAP_STR Mixed case Instr The instr function, which can be translated to mean “in string,” searches the first string for the second string and returns the position. You can specify where to start searching in the string and which occurrence to find. SELECT instr(‘tripper’,’rip’) AS rip_pos, instr(‘tripper’,’trip’) AS trip_pos, instr(‘tripper’,’per’) AS rep_pos, instr(‘tripper’,’xxx’) AS xxx_pos FROM dual Table 8.65 lists the results. Table 8.65 Instr Simple Results RIP_POS TRIP_POS REP_POS XXX_POS 2150 Oracle SQL 201 SELECT instr(‘00-11-00-11-00-11’,’00’,2) AS start_1, instr(‘00-11-00-11-00-11’,’00’,2,2) AS start_2_get_2 FROM dual Table 8.66 lists the results. Table 8.66 Instr Position and Instance Results START_1 START_2_GET_2 713 Instrb The instrb function provides the same functionality of instr but returns the byte position. This is advantageous when multibyte character sets are used. It searches the first string for the second string and returns the position. You can specify where to start searching in the string and which occurrence to find. SELECT instr(‘tripper’,’rip’) AS rip_pos, instr(‘tripper’,’trip’) AS trip_pos, instr(‘tripper’,’per’) AS rep_pos, instr(‘tripper’,’xxx’) AS xxx_pos FROM dual Table 8.67 lists the results. Table 8.67 Instr Simple Results RIP_POS TRIP_POS REP_POS XXX_POS 21 50 SELECT instr(‘00-11-00-11-00-11’,’00’,2) AS start_1, instr(‘00-11-00-11-00-11’,’00’,2,2) AS start_2_get_2 FROM dual Table 8.68 lists the results. Table 8.68 Instr Position and Instance Results START_1 START_2_GET_2 713 202 Chapter 8 Least The least function returns the alphanumerically least string in its parameter list. Numbers and dates can be intermixed in the parameter list, but dates use the default date mask. It’s best to convert dates to strings first with the to_char function. SELECT least(‘DOH1’,ename,job,’DOH2’) AS least_str FROM emp,dept WHERE emp.deptno=dept.deptno AND emp.deptno=10 Table 8.69 lists the results. Table 8.69 Least Results LEAST_STR CLARK DOH1 CLERK Length The length function returns the number of characters in the string. SELECT dname,length(dname) AS length FROM dept Table 8.70 lists the results. Table 8.70 Length Results DNAME LENGTH ACCOUNTING 10 RESEARCH 8 SALES 5 OPERATIONS 10 Oracle SQL 203 Lengthb The lengthb function returns the number of bytes in the string. This function is advantageous when multibyte character sets are used. SELECT dname,length(dname) AS length FROM dept Table 8.71 lists the results. Table 8.71 Length Results DNAME LENGTH ACCOUNTING 10 RESEARCH 8 SALES 5 OPERATIONS 10 Lower The lower function changes all letters to lowercase. SELECT lower(‘mIXeD CaSE’) AS lower_str FROM DUAL Table 8.72 lists the results. Table 8.72 Initcap Results INITCAP_STR mixed case Lpad The lpad function guarantees the length of the string by prefixing characters or trun- cating. By default, spaces are the pad character, but this can be specified. SELECT dname, lpad(dname,8) AS space_pad, lpad(dname,8,’-’) AS dash_pad FROM dept Table 8.73 lists the results. 204 Chapter 8 Table 8.73 Lpad Results DNAME SPACE_PAD DASH_PAD ACCOUNTING ACCOUNTI ACCOUNTI RESEARCH RESEARCH RESEARCH SALES SALES SALES OPERATIONS OPERATIO OPERATIO Ltrim The ltrim trims characters from the left side. By default, spaces are trimmed, but the strings to trim can be specified. SELECT ltrim(‘ string’) AS trim_str, ltrim(‘####string’,’#’) AS single_char_trim, ltrim(‘/**string’,’*/’) AS multi_char_trim FROM dual Table 8.74 lists the results. Table 8.74 Ltrim Results TRIM_STR SINGLE_CHAR_TRIM MULTI_CHAR_TRIM string string string Nls_initcap The nls_initcap function capitalizes the first letter and lowercases all other letters, based on the national character set. SELECT nls_initcap(‘mIXeD CaSE’) AS initcap_str FROM DUAL Table 8.75 lists the results. Table 8.75 Initcap Results INITCAP_STR Mixed case Oracle SQL 205 Nls_lower The nls_lower function changes all letters to lowercase, based on the national char- acter set. SELECT nls_lower(‘mIXeD CaSE’) AS lower_str FROM DUAL Table 8.76 lists the results. Table 8.76 Initcap Results INITCAP_STR mixed case Nls_upper The nls_upper function changes all letters to lowercase. SELECT nls_upper(‘mIXeD CaSE’) AS upper_str FROM DUAL Table 8.77 lists the results. Table 8.77 Upper Results UPPER_STR MIXED CASE Nls_sort The nls_sort function returns the byte sequence used to sort a string. Replace The replace function replaces one substring with another in your string. SELECT replace(‘good or bad’,’or’,’and’) replace_str FROM dual 206 Chapter 8 Table 8.78 lists the results. Table 8.78 Replace Results REPLACE_STR good and bad Rpad The rpad function guarantees the length of the string by suffixing characters or trun- cating. By default, spaces are the pad character, but this character can be specified. SELECT dname, rpad(dname,8) AS space_pad, rpad(dname,8,’-’) AS dash_pad FROM dept Table 8.79 lists the results. Table 8.79 Rpad Results DNAME SPACE_PAD DASH_PAD ACCOUNTING ACCOUNTI ACCOUNTI RESEARCH RESEARCH RESEARCH SALES SALES SALES OPERATIONS OPERATIO OPERATIO Rtrim The rtrim function trims characters from the right side. By default, spaces are trimmed, but the characters to trim can be specified. SELECT ltrim(‘string ‘) AS trim_str, ltrim(‘string####’,’#’) AS single_char_trim, ltrim(‘string**/’,’/*’) AS multi_char_trim FROM dual Oracle SQL 207 Table 8.80 lists the results. Table 8.80 Ltrim Results TRIM_STR SINGLE_CHAR_TRIM MULTI_CHAR_TRIM string string string Soundex Soundex is used to derive a phonetic pronunciation of the input string. It is used to help in cases where a string may not be spelled exactly right. The first letter is retained, all vowels h and y are dropped, and the remaining letters are encoded. SELECT soundex(dname) AS soundex_dname FROM dept Table 8.81 lists the result. Table 8.81 Soundex Results SOUNDEX_DNAME A253 R262 S420 O163 Substr The substr function returns a substring of the given string. The second parameter, if positive, is the character position where your desired substring starts. If negative, the position is an offset from the end of the string. By default, the string ends at the end of the string. If the third parameter is passed, it will specify the length of the string to extract. SELECT substr(dname,4) AS dname_4, substr(dname,-4) AS dname_neg4, substr(dname,2,3) AS dname_2_3, substr(dname,-3,2) AS dname_neg3_2 FROM dept Table 8.82 lists the results. 208 Chapter 8 Table 8.82 Substr Results DNAME_4 DNAME_NEG4 DNAME_2_3 DNAME_NEG3_2 OUNTING TING CCO IN EARCH ARCH ESE RC ES ALES ALE LE RATIONS IONS PER ON Substrb The substrb function returns a substring of the given string where the parameters refer to a byte position. It differs from substr only when a multibyte character set is used. The second parameter, if positive, is the byte position where your desired sub- string starts. If negative, the position is an offset from the end of the string. By default, the string ends at the end of the string. If the third parameter is passed, it will specify the length of the string in bytes to extract. SELECT substrb(dname,4) AS dname_4, substrb(dname,-4) AS dname_neg4, substrb(dname,2,3) AS dname_2_3, substrb(dname,-3,2) AS dname_neg3_2 FROM dept Table 8.83 lists the results. Table 8.83 Substrb Results DNAME_4 DNAME_NEG4 DNAME_2_3 DNAME_NEG3_2 OUNTING TING CCO IN EARCH ARCH ESE RC ES ALES ALE LE RATIONS IONS PER ON Translate The translate function changes one set of characters to another in the given string. SELECT translate(dname,’AEIOU’,’12345’) AS trans_str FROM dept Oracle SQL 209 [...]... LEAD_TRIM TRAIL_TRIM TRIM_CHAR string string string**** ****string Upper The upper function changes all letters to lowercase SELECT upper(‘mIXeD CaSE’) AS upper_str FROM DUAL Table 8.86 lists the results Oracle SQL Table 8.86 Upper Results UPPER_STR MIXED CASE Date Functions Date functions allow you to manipulate dates in SQL They are some of the most widely used functions in SQL With these functions you... the date SELECT hiredate, extract(YEAR FROM hiredate) AS year FROM emp WHERE deptno=10 Table 8.90 lists the results Table 8.90 Extract Results HIREDATE YEAR 09-JUN-81 1981 17-NOV-81 1981 23-JAN-82 1982 Oracle SQL Greatest The greatest function returns the greatest number in its parameter list Numbers and dates can be intermixed in the parameter list, but dates use the default date mask It’s best to convert... both dates fall on the last day of their respective months A negative number is returned if the first argument precedes the second argument You can use the abs function to always get a positive number Oracle SQL SELECT months_between(to_date(‘01-16’,’MM-DD’),to_date(‘08.16’,’MM-DD’)) AS btwn_1, months_between(to_date(‘08.16’,’MM-DD’),to_date(‘01-16’,’MM-DD’)) AS btwn_2, months_between(to_date(‘01-16’,’MM-DD’),to_date(‘08.31’,’MM-DD’))... Numtodsinterval Results HIREDATE DAYS HOURS MINUTES SECONDS 09-JUN-81 17-SEP-81 20-JUL-81 15-JUN-81 10-JUN-81 17-NOV-81 25-FEB-82 28-DEC-81 23-NOV-81 18-NOV-81 23-JAN-82 03-MAY-82 5-MAR-82 29-JAN-82 24-JAN-82 Oracle SQL Numtoyminterval The numtoyminterval function converts the parameter and interval year to month interval The string argument specifies the unit and can be either MONTH or YEAR SELECT hiredate,... function returns the system date from the dual table SELECT to_char(sysdate,’YYYY-MM-DD HH24:MM:SS’) date_str FROM dual Table 8.103 lists the results Table 8.103 Sysdate Results DATE_STR 2002-05-19 01:05:46 Oracle SQL Systimestamp The systimestamp function returns the system date and time, including fractional seconds and timezone information SELECT systimestamp FROM dual Table 8.104 lists the results Table . dual Table 8.65 lists the results. Table 8.65 Instr Simple Results RIP_POS TRIP_POS REP_POS XXX_POS 2150 Oracle SQL 201 SELECT instr(‘00-11-00-11-00-11’,’00’,2) AS start_1, instr(‘00-11-00-11-00-11’,’00’,2,2). results. Table 8.70 Length Results DNAME LENGTH ACCOUNTING 10 RESEARCH 8 SALES 5 OPERATIONS 10 Oracle SQL 203 Lengthb The lengthb function returns the number of bytes in the string. This function. initcap_str FROM DUAL Table 8.75 lists the results. Table 8.75 Initcap Results INITCAP_STR Mixed case Oracle SQL 205 Nls_lower The nls_lower function changes all letters to lowercase, based on the national

Ngày đăng: 03/07/2014, 08:20