advanced sql Functions in Oracle 10G phần 10 pptx

39 344 0
advanced sql Functions in Oracle 10G phần 10 pptx

Đ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

LOWER This function converts every letter of a string to lower - case. The general format for this function is: LOWER(string) For example, the query: SELECT LOWER('PUTS IN LOWERCASE') FROM dual Will give: LOWER('PUTSINLOWER puts in lowercase LPAD This function makes a string a certain length by adding (padding) a specified set of characters to the left of the original string. LPAD stands for “left pad.” The gen- eral format for this function is: LPAD(string, length_to_make_string, what_to_add_to_left_of_string) For example, the query: SELECT LPAD('Column', 15, '.') FROM dual Will give: LPAD('COLUMN',1 Column 360 String Functions LTRIM This function removes a set of characters from the left of a string. LTRIM stands for “left trim.” The general format for this function is: LTRIM(string, characters_to_remove) For example, the query: SELECT LTRIM(' Mitho', '.') FROM dual Will give: LTRIM Mitho REGEXP_INSTR This function returns the location (beginning) of a pat- tern in a given string. REGEXP_INSTR extends the regular INSTR string function by allowing searches of regular expressions. The simplest form of this function is: REGEXP_INSTR(source_string, pattern_to_find) This part works like the INSTR function. The general format for the REGEXP_INSTR function with all the options is: REGEXP_INSTR(source_string, pattern_to_find [, position, occurrence, return_option, match_parameter]) source_string is the string in which you wish to search for the pattern. 361 Appendix | A pattern_to_find is the pattern that you wish to search for in a string. position indicates where to start searching in source_string. occurrence indicates which occurrence of the pat - tern_to_find (in the source_string) you wish to search for. For example, which occurrence of “si” do you want to extract from the source string “Mississippi”. return_option canbe0or1.Ifreturn_option is 0, Ora - cle returns the first character of the occurrence (this is the default); if return_option is 1, Oracle returns the position of the character following the occurrence. match_parameter allows you to further customize your search. t “i” in match_parameter can be used for case- insensitive matching t “c” in match_parameter can be used for case- sensitive matching t “n” in match_parameter allows the period to match the new line character t “m” in match_parameter allows for more than one line in source_string For example, the query: SELECT REGEXP_INSTR('Mississippi', 'si', 1,2,0,'i') FROM dual Will give: REGEXP_INSTR('MISSISSIPPI','SI',1,2,0,'I') 7 362 String Functions REGEXP_REPLACE This function returns the source_string with every occurrence of the pattern_to_find replaced with the replace_string. The simplest format for this function is: REGEXP_REPLACE (source_string, pattern_to_find, pattern_to_replace_by) The general format for the REGEXP_REPLACE function with all the options is: REGEXP_REPLACE (source_string, pattern_to_find, [pattern_to_replace_by, position, occurrence, match_parameter]) For example, the query: SELECT REGEXP_REPLACE('Mississippi', 'si', 'SI', 1, 0, 'i') FROM dual Will give: REGEXP_REPL MisSIsSIppi REGEXP_SUBSTR This function returns a string of data type VAR - CHAR2 or CLOB. REGEXP_SUBSTR uses regular expressions to specify the beginning and ending points of the returned string. The simplest format for this function is: REGEXP_SUBSTR(source_string, pattern_to_find) 363 Appendix | A The general format for the REGEXP_SUBSTR func - tion with all the options is: REGEXP_SUBSTR(source_string, pattern_to_find [, position, occurrence, match_parameter]) For example, the query: SELECT REGEXP_SUBSTR('Mississippi', 'si', 1, 2, 'i') FROM dual Will give: RE si REPLACE This function returns a string in which every occur- rence of the pattern_to_find has been replaced with pattern_to_replace_by. The general format for this function is: REPLACE(source_string, pattern_to_find, pattern_to_replace_by) For example, the query: SELECT REPLACE('Mississippi', 'pi', 'PI') FROM dual Will give: REPLACE('MI MississipPI 364 String Functions RPAD This function makes a string a certain length by adding (padding) a specified set of characters to the right of the original string. RPAD stands for “right pad.” The general format for this function is: RPAD(string, length_to_make_string, what_to_add_to_right_of_string) For example, the query: SELECT RPAD('Letters', 20, '.') FROM dual Will give: RPAD('LETTERS',20,'. Letters RTRIM This function removes a set of characters from the right of a string. RTRIM stands for “right trim.” The general format for this function is: RTRIM(string, characters_to_remove) For example, the query: SELECT RTRIM('Computers', 's') FROM dual Will give: RTRIM('C Computer 365 Appendix | A SOUNDEX This function converts a string to a code value. Words with similar sounds will have a similar code value, so you can use SOUNDEX to compare words that are spelled slightly differently but sound basically the same. The general format for this function is: SOUNDEX(string) For example, the query: SELECT SOUNDEX('Time') FROM dual Will give: SOUN T500 String||String This function concatenates two strings. The general format for this function is: String||String For example, the query: SELECT 'This' || ' is '|| 'a' || ' concatenation' FROM dual Will give: 'THIS'||'IS'||'A'||'CON This is a concatenation 366 String Functions SUBSTR This function allows you to retrieve a portion of the string. The general format for this function is: SUBSTR(string, start_at_position, number_of_characters_ to_retrieve) For example, the query: SELECT SUBSTR('Mississippi', 5, 3) FROM dual Will give: SUB iss TRANSLATE This function replaces a string character by character. Where REPLACE looks for a whole string pattern and replaces the whole string pattern with another string pattern, TRANSLATE will only match characters (by character) within the string pattern and replace the string character by character. The general format for this function is: TRANSLATE(string, characters_to_find, characters_to_replace_by) For example, the query: SELECT TRANSLATE('Mississippi', 's','S') FROM dual 367 Appendix | A Will give: TRANSLATE(' MiSSiSSippi TRIM This function removes a set of characters from both sides of a string. The general format for this function is: TRIM ([{leading_characters | trailing_characters | both} [trim_character]) | trim_character} FROM | source_string) For example, the query: SELECT TRIM(trailing 's' from 'Cars') FROM dual Will give: TRI Car UPPER This function converts every letter in a string to upper - case. The general format for this function is: UPPER(string) For example, the query: SELECT UPPER('makes the string into big letters') FROM dual 368 String Functions Will give: UPPER('MAKESTHESTRINGINTOBIGLETTE MAKES THE STRING INTO BIG LETTERS VSIZE This function returns the storage size of a string in Oracle. The general format for this function is: VSIZE(string) For example, the query: SELECT VSIZE('Returns the storage size of a string') FROM dual Will give: VSIZE('RETURNSTHESTORAGESIZEOFASTRING') 36 369 Appendix | A [...]... analytical functions, partitioning, 135-136 aggregate functions, using in SQL, 111-115 aggregation, conditions for using, 191-193 alternation operator, 247 analytical functions, 53-55 adding to SELECT statement, 67-68, 71, 74 and partitioning, 95-96 changing ordering after adding, 75 execution order of, 65-77 performance implications of using, 80-86 using HAVING clause with, 76-77 using in a SQL statement,... 298-299, 325 NTILE function, using, 101 -105 null value function, 10- 12 nulls, 86 excluding, 92 handling with NVL function, 93-94 using in analytical functions, 86-95 using with NTILE function, 103 -105 NULLS FIRST option, 90-91 NULLS LAST option, 90-91 numbers, formatting, 35-39 numeric manipulation functions, 4-7 NVL function, 10 using, 10- 12 using to handle nulls, 93-94 Index O object specification,... IGNORE NAV clause, 171 INDEX-BY TABLE, 269 INITCAP function, 358 INSERT INTO function, using, 275 INSTR function, 18, 359 using, 18-19 ITERATE command, 214-221 iteration, finding square root with, 214-221 with MODEL statement, 211-214 J join, adding ordering to, 70 adding to SELECT statement, 68-69, 71 L LAG function, 146 using, 143-147 LAST function, using in a loop, 318-319 using with VARRAY, 312-316... function, 14 using, 15 COSH function, 16 using, 17 COUNT function, using, 126 using with VARRAY, 316-318 COVAR_POP function, 374 COVAR_SAMP function, 374 CREATE TABLE command, 279-280, 284 using, 274 using in VARRAY, 300 CREATE TYPE statement, 299 using in VARRAY, 299-300 CUBE function, 160-162 using with GROUPING function, 162-164 CUME_DIST function, 106 , 375 using, 106 -109 CUME_RANK function, 107 -108 CV... option, 183 using, 188 ROLLUP function, 157-160 using with GROUPING function, 162-164 ROUND function, 7 using, 8 -10, 113-115 row addresses, dereferencing, 286-287 row filter, 65 row objects, 279 creating table to reference, 284 loading table of, 281-282 referencing, 284 updating data in table of, 283 updating table containing, 285-286 using, 279-280 ROW_NUMBER function, 55, 59-60 using, 96 -100 ROWNUM... empty strings, 258-259 escape character, 262-263 EXISTS function, using with VARRAY, 312-316 EXP function, 12 using, 13 EXPLAIN PLAN command, 81 using, 82-85 exponential functions, 12-14 Extensible Markup Language, see XML external functions, using, 311-319 F FIRST function, using in a loop, 318-319 FLOOR function, 7 using, 8 FOR loop, 208-209 using, 209-211 using FIRST function in, 318-319 using LAST... 253, 363-364 using, 253-258 REGR function, 376-379 regular expressions, 223 using metacharacters with, 232-237 REM, 48-49 remarks, in scripts, 48-49 repeat operators, see quantifiers repeating group, 287 REPLACE function, 23, 364 using, 23-24 reporting tools, 31-32 REs, see regular expressions result sets, formatting, 32-39 grouping, 101 -105 ordering, 56-62, 70, 75, 96 -100 ordering and grouping, 74 RETURN... ordering, 198-206 automatic, 205 sequential, 205-206 output, see result sets OVER clause, 114-115 P partition, 99 summing within, 189-191 PARTITION BY clause, 95-96 partitioning, 95-96 with aggregate analytical functions, 135-136 PERCENT_RANK function, 106 using, 106 -109 PERCENTILE_CONT function, 376 PERCENTILE_DISC function, 376 PL /SQL, using to create functions, 311-319 Portable Operating System Interface,... 273-274 creating table that contains, 274 inserting values into, 275 using UPDATE with, 278-279 COLUMN_VALUE function, using with VARRAY, 307-309 columns, clearing, 39-40 formatting, 32-35, 277 Index selecting, 277-278 selecting in TCROs, 288-289 using RULES clause with, 174-178 comments, see remarks comparison operators, using, 184-186 COMPUTE command, 45 using, 45-48 CONCAT function, 358 CORR function,... negating, 241-243 CASE statement, 154-155 CAST function, using with VARRAY, 308-311 CEIL function, 7 using, 8 classes, bracketed, 243-247 creating in table, 274 CLEAR COLUMNS command, 39 CLEAR command, 39 collection objects, 269, 272-273 COLUMN command, 33 using, 33-39 column objects, 273 creating user-defined functions for, 292-297 column types, creating, 273-274 creating table that contains, 274 inserting . wish to search for in a string. position indicates where to start searching in source_string. occurrence indicates which occurrence of the pat - tern_to_find (in the source_string) you wish to search. give: LTRIM Mitho REGEXP_INSTR This function returns the location (beginning) of a pat- tern in a given string. REGEXP_INSTR extends the regular INSTR string function by allowing searches of regular. is: UPPER(string) For example, the query: SELECT UPPER('makes the string into big letters') FROM dual 368 String Functions Will give: UPPER('MAKESTHESTRINGINTOBIGLETTE MAKES THE STRING INTO

Ngày đăng: 08/08/2014, 18:21

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