Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 33 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
33
Dung lượng
496,61 KB
Nội dung
620 A.16 FACTS.SQL
end if;
exception when NO_DATA_FOUND then
insert into customer(customer_id,name,preferences)
values(customer_id_seq.nextval,vfullname,PREFERENCESCOLLECTION(vgenre))
returning customer_id into id;
end;
vcustomer_id := id;
dte := TO_DATE('31-12-2004','DD-MM-YYYY') - rand(500);
dbms_output.put_line(to_char(vcountry_id));
dte := (SYSDATE + 300) - rand(500);
dbms_output.put_line(to_char(vcountry_id)||','||dte);
insert into sales
(
sales_id
,musiccd_id
,customer_id
,retailer_id
,continent_id
,country_id
,list_price
,discount
,sale_price
,sale_date
,sale_qty
,shipping_cost
)
values
(
sales_id_seq.nextval
,vmusiccd_id
,vcustomer_id
,vretailer_id
,vcontinent_id
,vcountry_id
,vlist_price
,vdiscount
,ROUND(vlist_price * (1 - vdiscount),2)
,dte
,1
,0
);
commit;
Appendix_A.fm Page 620 Thursday, July 29, 2004 10:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
This page intentionally left blank
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
[...]... 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,... 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, 363 Please purchase PDF Split-Merge on www.verypdf.com to remove... 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,... 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... JOIN clause with, 217 JOIN clause without, 216 Online Transaction Processing (OLTP), 38 Operators, 124–31 arithmetic, 124, 125 concatenation, 124, 128 hierarchical query, 124, 128–29 logical, 105, 107, 124, 126–28 multiset, 43, 124, 129–31 precedence, 124 set, 124, 129, 285–86 types of, 124 user-defined, 124, 131 Oracle Advanced Queuing, 69 Index Please purchase PDF Split-Merge on www.verypdf.com to... aggregation using, 244 defined, 242 syntax, 244 Packages declaration section, 539 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Index defined, 535 for grouping 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... 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 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,... 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, 81 example, 84–85 illustrated, 85 See also Queries Joins ANSI format, 206–7 anti, 208, 230 complex, 208, 230–33, 368 cross, 207, 210–12 DML and views with, 440–41 equi, 208, 230 formats, 206–7... DBMS_REDEFINITION package, 412–13 DBMS _SQL package, 551 DDL, 15 automatic command commitment, 63 commands, 316 Oracle Database 10g, 40 DECODE function, 194–95, 197, 200, 201, 202 DEFINE command, 151 DELETE command, 334–36 for all rows, 336 defined, 316 for multiple rows, 334–35 for one row, 334 syntax, 333 Deleting rows, 334–36 all, 336 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark... also Single-row functions Structured Query Language See SQL Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Index SUBMULTISET, 133 Subqueries, 85, 86, 267–84 comparison conditions and, 269–70 correlated, 268, 279–80 defined, 81, 267 demonstrating, 270–83 example, 85 illustrated, 86 inline view, 268, 281–82 inserting with, 324–25 in INSERT statement, 283 multiple-column, 268, . following URL, along with many other goodies, including my
resume:
www.oracledbaexpert.com /oracle/
OracleSQLJumpstartWithExamples/index.html
www.oracledbaexpert.com/resume/resume.doc
. addresses:
oracledbaexpert@earthlink.net
carolmdieter@yahoo.com
Oracle Technology Network at http://technet .oracle. com or http://
otn .oracle. com