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

32 282 0
Tài liệu Oracle SQL Jumpstart with Examples- P15 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

A.16 FACTS.SQL 621 Appendix A exception when others then dbms_output.put_line('PROC: factGenerate '||SQLERRM(SQLCODE)); rollback; end; / create or replace procedure facts (i IN integer) is j integer; begin for j in 1 i loop factsGenerate; delay(10000000); dbms_output.put_line('Facts: '||to_char(j)); end loop; end; / set serveroutput on; exec dbms_output.enable(10000000); set timing on; truncate table sales; exec facts(1000); exec dbms_output.disable; set serveroutput off; declare cursor cSales is select * from sales order by sale_qty; begin for rSales in cSales loop update sales set sale_date = (SYSDATE + 300) - rand(500); commit; end loop; end; / SPOOL OFF; Appendix_A.fm Page 621 Thursday, July 29, 2004 10:17 PM This page intentionally left blank 623 B Please note that these scripts should be tested before use in a production environment. B.1 Tables set wrap off linesize 132 pages 80 column tab format a20 column col format a15 column pos format 990 column typ format a10 column tbs format a25 BREAK ON tab NODUPLICATES SKIP 2 ON NAME NODUPLICATES select t.table_name "Tab" ,c.column_name "Col" ,c.column_id "Pos" ,c.data_type "Typ" ,DECODE(c.nullable,'N','NOT NULL',NULL) "Null" ,t.tablespace_name "Tbs" from user_tables t, user_tab_columns c where t.table_name = c.table_name order by t.table_name, c.column_id; B.2 Constraints set wrap off linesize 132 pages 80 column tab format a20 column key format a10 column cons format a20 column col format a10 Appendix_B.fm Page 623 Thursday, July 29, 2004 10:17 PM 624 B.3 Indexes column pos format 990 BREAK ON tab NODUPLICATES SKIP 2 ON NAME NODUPLICATES select t.table_name "Tab" ,decode(t.constraint_type,'P','Primary','R','Foreign','U','Alternate','Unknown') "Key" ,t.constraint_name "Cons" ,c.column_name "Col" ,c.position "Pos" from user_constraints t, user_cons_columns c where t.constraint_type in ('P','R','U') and t.table_name = c.table_name and t.constraint_name = c.constraint_name order by t.table_name, t.constraint_type, c.position; B.3 Indexes set wrap off linesize 132 pages 80 column tab format a25 column typ format a5 column ind format a25 column col format a20 column pos format 990 column tbs format a25 BREAK ON tab NODUPLICATES SKIP 2 ON NAME NODUPLICATES Select t.table_name "Tab" ,decode(t.index_type,'NORMAL','BTree','BITMAP','Bitmap','FUNCTION-BASED NORMAL','Function-Based BTree',t.index_type) "Typ" ,t.index_name "Ind" ,c.column_name "Col" ,c.column_position "Pos" ,t.tablespace_name "Tbs" from user_indexes t, user_ind_columns c where t.table_name = c.table_name and t.index_name = c.index_name and t.index_type not in ('IOT - TOP','LOB') order by t.table_name, t.index_name, c.column_position; Appendix_B.fm Page 624 Thursday, July 29, 2004 10:17 PM 625 C The authors of this book can be contacted at the following e-mail addresses:  oracledbaexpert@earthlink.net  carolmdieter@yahoo.com Oracle Technology Network at http://technet.oracle.com or http:// otn.oracle.com is an excellent source for entire Oracle reference docu- mentation sets. Metalink at http://metalink.oracle.com is also excellent and a source of current information from support calls, questions, and answers placed by both Oracle users and Oracle support staff. The information on this site is well worth the Oracle licensing fees required. Search for a term such as “free buffer waits” in search engines such as www.yahoo.com. Be aware that not all information will be current and might be incorrect. Verify any information found on Oracle Technet. If no results are found using Yahoo, try the full detailed listings on www.google.com. Try www.amazon.com and www.barnesandnoble.com, where many Oracle titles can be found. C.1 Other titles by the authors: Gavin Powell (www.oracledbaexpert.com) Oracle Performance Tuning for 9 i and 10 g (ISBN: 1-555-58305-9). Introduction to Oracle 9 i and Beyond: SQL & PL/SQL (ISBN: 1-932- 07224-1). Appendix_C.fm Page 625 Thursday, July 29, 2004 10:18 PM 626 C.1 Other titles by the authors: Oracle Database Administration Fundamentals I (ISBN: 1-932-07253-5). Oracle Database Administration Fundamentals II (ISBN: 1-932-07284-5). Oracle SQL Exam Cram 2 (ISBN: 0-789-73248-3). Carol McCullough-Dieter Oracle9i Database Administrator: Implementation and Administration (ISBN: 0-619-15900-6). Oracle9i for Dummies (ISBN: 0-764-50880-6). Oracle8i DBA Bible (ISBN: 0-764-54623-6). Oracle8i for Dummies (ISBN: 0-764-50798-2). Several other out-of-print books MUSIC schema scripts can be found from a simple menu on my Web site at the following URL, along with many other goodies, including my resume: www.oracledbaexpert.com/oracle/ OracleSQLJumpstartWithExamples/index.html www.oracledbaexpert.com/resume/resume.doc Software accreditations:  Microsoft Word, Powerpoint, Excel, Win2K.  ERWin.  Paintshop.  Oracle Database 10 g and Oracle Database 9 i . Appendix_C.fm Page 626 Thursday, July 29, 2004 10:18 PM 627 Index ; (semicolon), 7 < > (angle brackets), 17–18 "" (double quotes, 78 / (forward slash), 76 % (percentage character), 82, 102 | (pipe character), 18 _ (underscore character), 102 ABS function, 182 ADD_MONTHS function, 186 Aggregate functions AVG, 238 CORR, 239 COUNT, 238 COVAR_POP, 239 COVAR_SAMP, 239 CUME_DIST, 240 defined, 176, 237 DENSE_RANK, 240 GROUP_ID, 240 grouping, 240 GROUPING(), 240 GROUPING_ID, 241 HAVING clause with, 255 MAX, 238 MEDIAN, 239 MIN, 238 Oracle, using, 238 PERCENTILE, 240 PERCENT_RANK, 240 RANK, 240 ranking, 240 REGR, 239 simple summary, 238 statistical calculators, 238–39 statistical distribution, 240 STATS, 239 STDDEV, 238 STDDEV_POP, 238 STDDEV_SAMP, 239 SUM, 238, 242 VARIANCE, 238 VAR_POP, 239 VAR_SAMP, 239 See also Group functions Aliases column, 78, 79, 112 table, 79 ALL clause, 246–49 ALTER CLUSTER command, 485 ALTER INDEX command, 482 syntax, 482 using, 483 ALTER ROLE command, 523–24 ALTER SEQUENCE command, 493 ALTER TABLE command, 298, 450, 460– 61 constraints and, 461–64 constraints syntax, 461 index.fm Page 627 Thursday, July 29, 2004 10:37 PM 628 Index syntax, 408 ALTER USER command, 509 ALTER VIEW command, 434, 450 constraints syntax, 461 syntax, 534 American National Standards Institute (ANSI), 15–16 JOIN clause, 206–7 mutable joins, 232 Analytical functions, 176 AND operator, 105, 107, 126 example, 126 illustrated, 126 See also Logical operators Angle brackets (< >), 17–18 Anti-joins, 230 avoiding, 230 defined, 208 Archiving, 61–62 Arithmetic operations, 91–92 Arithmetic operators, 125 defined, 124 example, 125 illustrated, 125 See also Operators Associative arrays, 542 AVG function, 238 Backus-Naur syntax conventions, 75 Base tables, 426 BETWEEN conditional comparison, 104 BFILE datatype BFILENAME function, 347 defined, 343 example, 345–47 use illustration, 346 use of, 343 using, 345–47 BFILENAME function, 347 BINARY_DOUBLE datatype, 341 BINARY_FLOAT datatype, 341 Binary floating-point number, 185–86 BINARY_INTEGER datatype, 541 Bitmap indexes defined, 477 WHERE clause and, 486 See also Indexes Bitmap join indexes, 478, 483 BLOB datatype, 55, 342, 343 BOOLEAN datatype, 541 BREAK command COMPUTE command and, 164 defined, 162 example, 162, 163 syntax, 162 BTITLE command, 160 BTree indexes, 474–75 defined, 474–75 illustrated, 476 CARDINALITY function, 354 CASCADE clause, 466–68 CASE statements, 556–60 defined, 302 search condition, 556, 557–58 searched, 304 selector and expression, 556, 558–60 syntax, 303, 557 use of, 556 See also Control structures CAST function, 353 CEIL function, 182 CHAR datatype, 340, 401 Check constraints, 456–58 defined, 449 inline, 456 out-of-line, 456 using, 458 See also Constraints CLOB datatype, 342, 343, 374 index.fm Page 628 Thursday, July 29, 2004 10:37 PM Index 629 Index Clustering, 70–71 Clusters, 484–87 CREATE TABLE syntax for, 486 creating, 485–87 defined, 386, 475–76, 484–85 hash, 485 regular, 485 sorted hash, 485 types of, 485 See also Indexes COALESCE function, 194 COLLECT function, 353 Collections, 43 nested table, 350–52 object, 348–54 COLUMN command column alias, 158 formatting, turning off, 156 settings, 154 on single line, 158 syntax, 154 use illustration, 156 using, 155–56 Columns adding, 408–09 aliases, 78, 79, 112 changing, 409–11 datatypes, 53, 55 formatting, 154–60 names, 53–54 non-nullable, 411 removing, 411–12 renaming, 411 selecting, 55 unused, 411 updating, 332 See also Rows; Tables Comments adding, 416–20 inline, 419–20 multiple-line, 419 for schema objects, 416–19 single-line, 420 See also Tables COMMIT command, 62–64 execution, 63, 64, 317 ROLLBACK command comparison, 63– 64 saving changes with, 317 Comparison conditions defined, 131 EXISTS, 272 IN, 273, 274 multiple-row subqueries, 272 subqueries and, 269–70 Complex joins, 230–33 defined, 208, 230–31 illustrated, 368, 369 See also Joins Complex views creating, 430–33 defined, 427 See also Views Composite partitions, 68, 402 Composite queries, 88 defined, 81, 285 example, 88 set operators, 285–86 using, 286–89 See also Queries Compound expressions, 302 COMPUTE command, 163 BREAK command and, 164 defined, 163 syntax, 164 Concatenation operator, 128 defined, 124 example, 128 See also Operators CONCAT function, 180 Conditional comparisons ALL, 104–5 index.fm Page 629 Thursday, July 29, 2004 10:37 PM 630 Index anti (!=, <>), 102 ANY, 104–5 BETWEEN, 104 defined, 101 equi (=), 102 EXISTS, 103–4 IN, 103 LIKE, 102 range (<, >, =<, >=), 102 SOME, 104–5 types of, 102–5 Conditions, 131–33 comparison, 131, 269–70 defined, 131 floating-point, 131 NULL, 131–32 object collection, 132–33 XML, 132 CONNECT BY clause, 39 CONNECT_BY_ROOT operator defined, 128, 290 illustrated, 292 using, 290–92 Constraints, 447–69 adding, to existing tables, 462–63 ALTER TABLE command and, 461–64 applying, 449 cascading of, 468 check, 449, 456–58 defined, 448 dropping, 465–68 dropping, with CASCADE clause, 466–68 ENABLE/DISABLE states, 463–64 EXCEPTIONS clause, 464 foreign key, 447, 449, 452–56 function of, 447 inline, 448 managing, 449–60 metadata views, 469 modifying, on existing tables, 463 NOT NULL, 448 out-of-line, 448, 453–56 primary key, 447, 449, 451–52 REF, 449, 459–60 Referential Integrity, 465 RELY state, 464 renaming, 464–65 states, 463–64 types, 448–49 unique, 448, 451–52 uses, 448–49 USING INDEX clause, 464 Constraint views creating, 429–30 defined, 427 inserted rows requirement, 431 inserting/updating rows with, 439 See also Views Controlfiles, 61 Control structures, 553–67 CASE statement, 556–60 FORALL command, 561, 565 FOR loop, 560, 561–63 GOTO statement, 565, 566 IF statement, 554–56 iteration/repetition, 554, 560–65 LOOP END LOOP, 561, 564–65 NULL statement, 565, 566–67 selection, 553, 554–60 sequence controls, 554, 565–67 types of, 553–54 WHILE loop, 560, 563–64 Conversion functions, 190–94 date formats, 191–94 defined, 177 illustrated, 179 importance, 190 number formats, 190–91 TO_CHAR, 190, 193 TO_CLOB, 190 TO_DATE, 190, 201, 202 TO_N, 190 index.fm Page 630 Thursday, July 29, 2004 10:37 PM [...]... illustration, 27 scroll bar, 26 steps, 24–28 use of, 19 See also SQL tools SQL* Plus Worksheet, 28–31 Index defined, 19 logging into, 29 starting, 29 steps, 29–30 versatility, 30 Windows-like functions, 30 See also SQL tools SQL tools, 19–34 iSQL*Plus, 19, 31–34 SQL* Plus Command Line, 19–24 SQL* Plus Windows, 19, 24–28 SQL* Plus Worksheet, 19, 28–31 SQL/ XML standard, 363–72 SQRT function, 184 Standby databases,... of, 260 using, 262–66 versatility, 266 SQL defined, 14 origins, 14–15 SQL* PLUS environmental settings, 137–48 iSQL*Plus vs., 168, 171 query output format, 153–65 report layout, 77 scripts, 151–53 using, 137–74 variables, 148–51 SQL* Plus Command Line disadvantages, 23 line editing commands, 24 startup steps, 21–23 use of, 19 in Windows 2000, 22 See also SQL tools SQL* Plus Windows, 24–28 menu, 26 screen... on Windows 2000, NT, XP, 52 XML improvements, 45 Oracle Enterprise Manager (OEM), 28, 386– 87 Console, 28 in table creation, 388 Oracle Expression Filter, 44, 309–14 applying, 312 defined, 309 listing with, 314 using, 309–14 See also Expressions Oracle instance, 58–59 background processes, 59 defined, 58 foreground processes, 59 memory buffers, 58 Oracle SQL defined, 15 Index functions, 363 introduction,... output, 168 primary interface, 167 query processing, 167 query results, 33 SQL* Plus vs., 168, 171 steps, 31–34 troubleshooting, 171–72 using, 165–74 variables, 171 See also SQL tools ITERATION_NUMBER function, 262 Java, improvements in Oracle Database 10g, 45 JOIN clause, 205, 206–7 with ON clause, 217 syntax, 207 use of, 207 without ON clause, 216 Joining tables, 205–33 Join queries, 84–85 defined,... returning data from, 48 documents, storage, 378 element tags, 364 element tags with tag attributes, 365 functional capability enhancements, 47 functions, 47–48 generating, from Oracle SQL code, 48 generating, from tables, 362–73 generation format, 368 improvements in Oracle Database 10g, 45 object hierarchical nature, 370 using, in Oracle, 360–80 XMLAGG function, 363, 365, 371, 372 XMLATTRIBUTES function,... 324–25 sequences in, 496–97 subqueries, 281 Inserting rows with INSERT command, 324–30 one, 325–26 with subquery, 326–27 See also Rows IN set membership, 103 INSTR function, 180 INTEGER datatype, 340, 401 INTERSECT operator defined, 129, 286 returns, 287, 288 IS ANY, 133 IS A SET condition, 133 IS EMPTY, 133 IS OF TYPE, 133 IS PRESENT, 133 ISQL*Plus, 17, 31–34 defined, 19 direct database access, 32 display,... procedures, 541 Oracle- provided, 567–68 using, 539–41 Parallel queries, 297–99 defined, 81, 89 execution methods, 298 SQL types and, 298 use of, 297–98 See also Queries Partitioned tables creating, 402–6 defined, 384 Partitions, 67–68 composite, 68, 402 hash, 68, 402, 404–5 indexing, 402–3 list, 67–68, 402 range, 67, 402 range-hash, 68, 402, 405, 406 range-list, 68, 402, 405–6 types of, 402 working with, 68... changing, with ALTER USER command, 509 modifying, 509–10 Percentage character (%), 82, 102 PERCENTILE function, 240 PERCENT_RANK function, 240 Performance views defined, 442 listing, 443 Physical standby databases, 70 PL /SQL, 531–68 blocks and exception trapping, 533–34 changing data in, 549–50 compiler, 44 control structures, 553–67 datatypes, 541–43 defined, 531 643 downside, 532 dynamic SQL, 550–53... 549–50 compiler, 44 control structures, 553–67 datatypes, 541–43 defined, 531 643 downside, 532 dynamic SQL, 550–53 functions, 175, 535–37 improvements in Oracle Database 9i, 48– 49 improvements in Oracle Database 10g, 44–45 objects and methods, 567 Oracle- provided packages, 567–68 packages, 535, 539–41 procedures, 534, 535 as programming language, 532–41 quoting of strings, 45 retrieving data in, 543–49... defined, 258 example, 259 subtotals, 259 Hash clusters, 485 Hash partitions, 68 CREATE TABLE syntax, 404–5 defined, 402 See also Partitions HAVING clause, 236 with aggregate functions, 255 filtering grouped results with, 253–55 restricting groups with, 254 Hierarchical data model, 2 Hierarchical queries, 86–88, 289–92 CONNECT_BY_ROOT, 128 defined, 81, 289 example, 86–88, 290–92 Index illustrated, 87, 291 . following URL, along with many other goodies, including my resume: www.oracledbaexpert.com /oracle/ OracleSQLJumpstartWithExamples/index.html www.oracledbaexpert.com/resume/resume.doc . authors: Oracle Database Administration Fundamentals I (ISBN: 1-932-07253-5). Oracle Database Administration Fundamentals II (ISBN: 1-932-07284-5). Oracle SQL

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

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