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

Tài liệu Oracle SQL Jumpstart with Examples- P14 pdf

33 346 0
Tài liệu đã được kiểm tra trùng lặp

Đ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

Thông tin cơ bản

Tiêu đề Tài liệu Oracle SQL Jumpstart with Examples- P14 pdf
Trường học University of the People
Chuyên ngành Database Management
Thể loại Lecture notes
Thành phố Los Angeles
Định dạng
Số trang 33
Dung lượng 496,61 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

This page intentionally left blank... Appendix_B.fm Page 623 Thursday, July 29, 2004 10:17 PMPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark... 624 B.3 Indexe

Trang 1

620 A.16 FACTS.SQL

end if;

exception when NO_DATA_FOUND then

insert into customer(customer_id,name,preferences)

Trang 2

A.16 FACTS.SQL 621

Appendix A

exception when others then

dbms_output.put_line('PROC: factGenerate '||SQLERRM(SQLCODE));

set timing on;

truncate table sales;

for rSales in cSales loop

update sales set sale_date = (SYSDATE + 300) - rand(500);

Trang 3

This page intentionally left blank

Trang 4

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.

Trang 5

624 B.3 Indexes

column pos format 990

BREAK ON tab NODUPLICATES SKIP 2 ON NAME NODUPLICATES

select t.table_name "Tab"

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;

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

Trang 6

Metalink at http://metalink.oracle.com is also excellent and a source ofcurrent information from support calls, questions, and answers placed byboth Oracle users and Oracle support staff The information on this site iswell worth the Oracle licensing fees required.

Search for a term such as “free buffer waits” in search engines such aswww.yahoo.com Be aware that not all information will be current and might

be incorrect Verify any information found on Oracle Technet If no resultsare found using Yahoo, try the full detailed listings on www.google.com.Try www.amazon.com and www.barnesandnoble.com, where manyOracle titles can be found

Gavin Powell (www.oracledbaexpert.com)

Oracle Performance Tuning for 9i and 10g (ISBN: 1-555-58305-9).Introduction to Oracle 9i 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.

Trang 7

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 Website at the following URL, along with many other goodies, including myresume:

www.oracledbaexpert.com/oracle/

OracleSQLJumpstartWithExamples/index.html www.oracledbaexpert.com/resume/resume.doc

Software accreditations:

 Microsoft Word, Powerpoint, Excel, Win2K

 ERWin

 Paintshop

 Oracle Database 10g and Oracle Database 9i

Appendix_C.fm Page 626 Thursday, July 29, 2004 10:18 PM

Trang 8

% (percentage character), 82, 102

| (pipe character), 18_ (underscore character), 102

ABS function, 182ADD_MONTHS function, 186Aggregate functions

AVG, 238CORR, 239COUNT, 238COVAR_POP, 239COVAR_SAMP, 239CUME_DIST, 240defined, 176, 237DENSE_RANK, 240GROUP_ID, 240grouping, 240GROUPING(), 240GROUPING_ID, 241HAVING clause with, 255MAX, 238

MEDIAN, 239MIN, 238Oracle, using, 238PERCENTILE, 240

PERCENT_RANK, 240RANK, 240

ranking, 240REGR, 239simple summary, 238statistical calculators, 238–39statistical distribution, 240STATS, 239

STDDEV, 238STDDEV_POP, 238STDDEV_SAMP, 239SUM, 238, 242VARIANCE, 238VAR_POP, 239VAR_SAMP, 239

Aliasescolumn, 78, 79, 112table, 79

ALL clause, 246–49ALTER CLUSTER command, 485ALTER INDEX command, 482syntax, 482

using, 483ALTER ROLE command, 523–24ALTER SEQUENCE command, 493ALTER TABLE command, 298, 450, 460–

61constraints and, 461–64constraints 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.

Trang 9

628 Index

syntax, 408ALTER USER command, 509

ALTER VIEW command, 434, 450

constraints syntax, 461syntax, 534

American National Standards Institute

(ANSI), 15–16JOIN clause, 206–7mutable joins, 232Analytical functions, 176

AND operator, 105, 107, 126

example, 126illustrated, 126

See also Logical operatorsAngle brackets (< >), 17–18

Anti-joins, 230

avoiding, 230defined, 208Archiving, 61–62

Arithmetic operations, 91–92

Arithmetic operators, 125

defined, 124example, 125illustrated, 125

See also OperatorsAssociative arrays, 542

example, 345–47use illustration, 346use of, 343

using, 345–47BFILENAME function, 347

BINARY_DOUBLE datatype, 341

BINARY_FLOAT datatype, 341Binary floating-point number, 185–86BINARY_INTEGER datatype, 541Bitmap indexes

defined, 477WHERE clause and, 486

See also IndexesBitmap join indexes, 478, 483BLOB datatype, 55, 342, 343BOOLEAN datatype, 541BREAK commandCOMPUTE command and, 164defined, 162

example, 162, 163syntax, 162BTITLE command, 160BTree indexes, 474–75defined, 474–75illustrated, 476

CARDINALITY function, 354CASCADE clause, 466–68CASE statements, 556–60defined, 302

search condition, 556, 557–58searched, 304

selector and expression, 556, 558–60syntax, 303, 557

use of, 556

See also Control structuresCAST function, 353

CEIL function, 182CHAR datatype, 340, 401Check constraints, 456–58defined, 449

inline, 456out-of-line, 456using, 458

See also ConstraintsCLOB datatype, 342, 343, 374

index.fm Page 628 Thursday, July 29, 2004 10:37 PM

Trang 10

saving changes with, 317Comparison conditionsdefined, 131

EXISTS, 272

IN, 273, 274multiple-row subqueries, 272subqueries and, 269–70Complex joins, 230–33defined, 208, 230–31illustrated, 368, 369

See also JoinsComplex viewscreating, 430–33defined, 427

See also ViewsComposite partitions, 68, 402Composite queries, 88defined, 81, 285example, 88set operators, 285–86using, 286–89

See also QueriesCompound expressions, 302COMPUTE command, 163BREAK command and, 164defined, 163

syntax, 164Concatenation operator, 128defined, 124

example, 128

See also OperatorsCONCAT function, 180Conditional comparisonsALL, 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.

Trang 11

adding, to existing tables, 462–63

ALTER TABLE command and, 461–64

Referential Integrity, 465RELY state, 464

renaming, 464–65states, 463–64types, 448–49unique, 448, 451–52uses, 448–49

USING INDEX clause, 464Constraint views

creating, 429–30defined, 427inserted rows requirement, 431inserting/updating rows with, 439

See also ViewsControlfiles, 61Control structures, 553–67CASE statement, 556–60FORALL command, 561, 565FOR loop, 560, 561–63GOTO statement, 565, 566

IF statement, 554–56iteration/repetition, 554, 560–65LOOP END LOOP, 561, 564–65NULL statement, 565, 566–67selection, 553, 554–60

sequence controls, 554, 565–67types of, 553–54

WHILE loop, 560, 563–64Conversion functions, 190–94date formats, 191–94defined, 177

illustrated, 179importance, 190number formats, 190–91TO_CHAR, 190, 193TO_CLOB, 190TO_DATE, 190, 201, 202TO_N, 190

index.fm Page 630 Thursday, July 29, 2004 10:37 PM

Trang 12

values passed into, 279

See also Subqueries

CORR function, 239

COUNT function, 238

COVAR_POP function, 239

COVAR_SAMP function, 239

CREATE INDEX command, 477, 478

CREATE ROLE command, 523

CREATE SEQUENCE command, 490

CREATE SESSION privilege, 507, 508

CREATE SYNONYM command, 499, 500

CREATE TABLE command, 298, 385, 386

with constraints syntax, 450

with detailed constraints syntax, 451

pseudo-like syntax, 389

as subquery, 387

syntax, 387–88

syntax for clusters, 486

syntax for external table, 398

syntax for hash partitions, 404–5

syntax for IOT, 397

syntax for list partitions, 403–4

syntax for object table, 391

syntax for range-hash partitions, 405, 406

syntax for range-list partitions, 405–6

syntax for range partitions, 403, 404

syntax for relational table, 390

syntax for temporary table, 393

CREATE VIEW command

See also JoinsCUBE clause, 257–58example, 257–58implementation, 258use of, 255, 257CUME_DIST function, 240CURRENT_DATE function, 186CURRENT_TIMESTAMP function, 186CURRENTV function, 261

CURRVAL pseudocolumn, 490, 495CURSOR expression, 302

Cursor FOR loop implicit cursor, 547–49defined, 547–48

example, 547–49illustrated, 549

See also Implicit cursorsCursors, 543–49

building, dynamically, 552–53explicit, 543–44

implicit, 544–49REF, 553

Database modelingevolution, 1–5file system, 1hierarchical, 2network, 3object, 3–4object-relational, 4–5relational, 3, 4, 8–14Databases

name, 20Oracle, evolution of, 6–8origin, 6

relational, 5–6spreadsheets vs., 52–53standby, 69–70XML and, 373–80

index.fm Page 631 Thursday, July 29, 2004 10:37 PM

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

Trang 13

632 Index

Data Definition Language See DDL

Data dictionary views, 442–45

column, 158formatting, 158–60Datetime functions, 186–89ADD_MONTHS, 186CURRENT_DATE, 186CURRENT_TIMESTAMP, 186defined, 177

EXTRACT, 187–89illustrated, 178LAST_DAY, 186LOCALTIMESTAMP, 186MONTHS_BETWEEN, 186NEXT_DAY, 186

ROUND, 187SYSDATE, 186SYSTIMESTAMP, 186TRUNC, 187, 200, 202

See also Single-row functionsDBMS_REDEFINITION package, 412–13DBMS_SQL package, 551

DDL, 15automatic command commitment, 63commands, 316

Oracle Database 10g, 40DECODE function, 194–95, 197, 200, 201,

202DEFINE command, 151DELETE command, 334–36for all rows, 336

defined, 316for multiple rows, 334–35for one row, 334

syntax, 333Deleting rows, 334–36all, 336

index.fm Page 632 Thursday, July 29, 2004 10:37 PM

Trang 14

DROP TABLE command, 414–15

DROP VIEW command, 434, 435

Environmental settingsadjusting, 171ARRAY[SIZE], 139AUTO[COMMIT], 139CMDS[EP], 139

COLSEP, 139default, 146defined, 138ECHO, 140ESC[APE], 140HEAD[ING], 140LINE[SIZE], 140LONG, 140MARK[UP] HTML, 141NEWP[AGE], 141NULL, 141–42NUMF[ORMAT], 142NUMW[IDTH], 142PAGES[IZE], 142PAU[SE], 142–43RECSEP, 143RECSEPCHAR, 143SERVEROUT[PUT], 143–44SQLP[ROMPT], 144

TERM[OUT], 146TIMI[NG], 146WRAP, 146

Environmental variables, 137Equi-joins, 230

defined, 208uses, 230EVALUATE operator, 44, 312Exception trapping, 533–34EXECUTE IMMEDIATE commanddefined, 550

index.fm Page 633 Thursday, July 29, 2004 10:37 PM

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

Trang 15

object type constructors, 305

Oracle Expression Filter and, 309–14

in ORDER BY clause, 119, 120

regular, 305–9

scalar subqueries, 302

types of, 302

eXtensible Markup Language See XML

eXtensible Style Sheets (XSL), 358

defined, 376demonstrating, 377, 378multiple-value pattern match and, 378single-value pattern match and, 378

Feature-related users, 505Fifth Normal Form (5NF), 10Filtered queries, 82–83defined, 81

example, 82illustrated, 83

See also QueriesFirst Normal Form (1NF), 8, 9Fishhook self-joins, 228–29Flashback queries, 292–97automated undo requirement, 293defined, 81, 292

execution, 295illustrated, 295syntax, 293–94using, 294–97versions, 293versions, illustrated, 296versions, with pseudocolumns, 297versions query pseudocolumns, 294

See also QueriesFLOAT datatype, 340Floating-point condition, 131FLOOR function, 182–83FORALL command, 561, 565Foreign key constraints, 447, 452–56defined, 449

indexes, 483nullable, 456out-of-line, 453–56table name, 453

index.fm Page 634 Thursday, July 29, 2004 10:37 PM

Trang 16

See also specific functions

Functions (PL/SQL)defined, 535using, 535–37

GETSTRINGVAL function, 369GETTIME function, 256, 257, 537GOTO statement, 565, 566

defined, 565example, 566GRANT command, 513, 518Granting privileges, 511–18object, 512

on roles, 524–27several users at once, 513system, 512

See also PrivilegesGREATEST function, 195GROUP BY clause, 249–60column list, 250, 253CUBE clause, 257–58execution, 250extending, 255–60GROUPING SETS clause, 258–60HAVING clause, 253–55

parts, 236ROLLUP clause, 256–57rules, 250

sort order, 252syntax, 235–36uses, 249using, 249–60Group functions, 91, 237–49aggregate, 237–44

ALL clause and, 246–49

index.fm Page 635 Thursday, July 29, 2004 10:37 PM

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

Trang 17

with aggregate functions, 255

filtering grouped results with, 253–55

restricting groups with, 254

Hierarchical data model, 2

using, 290–92

See also QueriesHierarchical query operators, 128–29, 290CONNECT_BY_ROOT, 290

defined, 124illustrated, 129PRIOR, 128, 290

See also OperatorsHierarchical self-joins, 228–29defined, 228

example, 229

See also Self-joinsHTML, embedding scripts in, 168–71HTTP Server

document directory, 169installation, 31

running iSQL*Plus, 168starting, 31

stopping/restarting, 172Hypertext Markup Language (HTML), 357documents, 357–58

Dynamic (DHTML), 358

IF statement, 554–56example, 554–56splitting results using, 556syntax, 554

Implicit cursors, 544–49cursor FOR loop, 547–49execution results, 545internal SQL, 545–47opening/closing, 544single-row SELECT, 547using, 546

See also Cursors

IN clause, 230

index.fm Page 636 Thursday, July 29, 2004 10:37 PM

Trang 18

See also Tables

Index-organized tables (IOTs), 475

INDEX tablespace, 61

INITCAP function, 180

Inline comments, 419–20Inline constraints

check, 456defined, 448Inline views, 281–82defined, 268example, 281–82multilayer nested, 282subquery, 432–33

See also SubqueriesInner joins, 212–17defined, 208illustrated, 209INSERT command, 324–30, 457, 458defined, 313

multiple-table, 325–28

in queries, 324–25sequences in, 496–97subqueries, 281Inserting rowswith INSERT command, 324–30one, 325–26

with subquery, 326–27

See also Rows

IN set membership, 103INSTR function, 180INTEGER datatype, 340, 401INTERSECT operatordefined, 129, 286returns, 287, 288

direct database access, 32display, customizing, 172–74environment, 34

environmental settings, 171

index.fm Page 637 Thursday, July 29, 2004 10:37 PM

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

Trang 19

Oracle proprietary format, 206outer, 208, 209, 210, 217–25range, 208, 230

right outer, 208, 210, 223–24self, 208, 225–29

types of, 207–10views with, 430–32

LAST_DAY function, 186Left outer joins, 218–23ANSI format, 221defined, 208example, 222illustrated, 209Oracle format, 220returns, 218–19

See also Outer joinsLENGTH function, 180LIKE comparison operator, 100, 102List partitions, 67–68

CREATE TABLE syntax, 403–4defined, 402

See also PartitionsLists, 300

LOCALTIMESTAMP function, 186Locks, 318–19

defined, 318table-level, 318LOCK TABLE command, 318–19Logging, 61–62

Logical operators, 126–28AND, 105, 107, 126defined, 124

NOT, 105, 128

OR, 105, 107, 127precedence, 126

See also Operators

index.fm Page 638 Thursday, July 29, 2004 10:37 PM

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

TỪ KHÓA LIÊN QUAN