Oracle Exams1z0 051

Embed Size (px)

Citation preview

  • 8/16/2019 Oracle Exams1z0 051

    1/17

    ExamEssentials N

    CH 1 Restricting and Sorting Data

    Understand the operators. Know the various operators that can be used inqueries.The

     parentheses around an expression change the precedence of the oper ator s.

    Understand the ORDER BY clause. The !"E! #$ clause is used to sort the result

    set from a quer%. $ou can specif% ascending order or descending order for the sort.

    &scending or der  is the default. &lso 'now that column alias names can be used in

    the !"E! #$ clause. $ou can also specif% columns b% their position.

    Know how to specify string literals using the operator.

    Know the order of clauses in the SELEC state!ent. The (E)ECT statement

    must have a *!+ clause. The ,HE!E clause- if it exists- should follow the *!+

    clause and precede the !"E! #$ clause.

    Literal Character Strings

    "ate and character literal values must be enclosed within single quotation mar's.

    (E)ECT last/name 00 is a 002ob/id

    &( 3Emplo%ee "etails3

    *!+ emplo%ees4

    Know the use of the DU"L ta#le. The "5&) table is a dumm% table in racle

    with one column and one row. This table is commonl% used to get the values ofs%stem variables such as ($("&TE or 5(E!.

    Know the characters used for pattern !atching. The 6 character is used to

    match 7ero or more characters .The / character is used to match one- and onl% one-

    character .The (8) operator used with a patternmatching character is )9KE.

    Know the sort order of $ULL %alues in&uiries with ORDER BY clause. #%

    default- in an ascendingorder s or the N5)) values appear at the bottom of the

    result set4 that is- N5))s are sorted higher. *or descendingorder sorts- N5))

    values appear at the top of the r esult set:again- N5)) values are sorted higher .

    ;age ' of '(

  • 8/16/2019 Oracle Exams1z0 051

    2/17

    ExamEssentials N

    CH < Using Single)Row *unctions to Custo!i+e Output

    Understand where single)row functions can #e used. (inglerow functions can

     be used in the (E)ECT- ,HE!E- and !"E! # $ clauses of (E)ECT statements.

    Know the effect sthat N5))%alues can ha%e on arith!etic and other functions.

    &n% ar ithmetic operation on a N5)) results in a N5)). This is true of most

    functions as well. 5se the N=)- N=)

  • 8/16/2019 Oracle Exams1z0 051

    3/17

    ExamEssentials N

    Understand the nu!eric functions. Know the effects of using T!5NC and !5N"

    with.nas the second argument. &lso practice using )EN>TH and 9N(T!- which

    return a numeric r esult- inside (5#(T! and other character f unctions.

    Know how date arith!etic wor-s. ,hen adding or subtracting numeric values

    from a "&TE datat%pe- whole numbers represent da%s. &lso- the date?time

    intervals 9NTE!=&) $E&! T +NTH and 9NTE!=&) "&$ T (ECN" can be added

    or subtracted from date?time datat%pes. $ou need to 'now how to interpret andcreate expressions that add intervals to or subtract intervals from dates.

    ;age  of '(

  • 8/16/2019 Oracle Exams1z0 051

    4/17

    ExamEssentials N

    Know the data types for the %arious date/ ti!e functions. racle has man%

    date?time f unctions to support the date?time datat%pes. $ou need to 'now the

    return datat%pes for these functions. ($("&TE and C5!!ENT/"&TE return a "&TE

    datat%pe. C5!!ENT/T9+E(T&+; and ($(T9+E(T&+; return a T9+E(T&+; ,9THT9+E@NE datat%pe. )C&)T9+E(T&+; returns a T9+E(T&+; datat% pe.

    Understand the use of the DECODE function. "EC"E acts li'e a case statement in

    C-;ascal- or &da.)earn how this function wor's and how to use it.

    ;age 0 of '(

  • 8/16/2019 Oracle Exams1z0 051

    5/17

    ExamEssentials N

    C1 Using Con%ersion *unctions and Conditional E2pressions

    Know the for!at !odels for con%erting dates to/ f ro! character strings. 9n

     practice- %ou can simpl% loo'up format codes in a reference .*or the certificationexam- %ou must have them memor i7ed.

    SQL> SELECT TO_DATE('01/01/05', 'DD/MM/YY') FROM DUAL;

     TO_DATE('

    ---------01-JAN-05 // ou!u "o#$% & #$&* + NLS_DATE_FORMAT//

    ;age 3 of '(

  • 8/16/2019 Oracle Exams1z0 051

    6/17

    ExamEssentials N

    TO_CHAR function.

    The TO_CHAR function converts a date or number to a TEXT expression in a

    specified format. This function is typically used to format output data.

    Note: Output format is specified in the expression itself.

    TO_NUMBER function.

    The TO_!"#ER function converts a formatted TEXT expression to a number.

    $E%ECT TO_!"#ER&'()*)+.,-' '%////.//'0 1RO" 2!A%RE$!%T3 )*)+.,-

    ;age 4 of '(

  • 8/16/2019 Oracle Exams1z0 051

    7/17

    ExamEssentials N

    CH A Reporting "ggregated Data Using the 5roup *unctions

    9t is important to understand the concept to grouping data- wher e >!5; #$

    and H&=9N> clauses can be used- and the rules associated with using these

    clauses.

    Except for C5NTBD- group functions ignore N5))s. ;r ogrammer written

    functions cannot be used as group functions. C5NT- (5+- and &=> are the

    most commonl% used group f unctions. ,hen using group functions or

    aggregate functions in a quer%-the columns that do not have an% aggregate

    function applied to them must appear in the >!5; #$ clause of the quer %.

    The H&=9N> clause is used to filter out data after the aggregates are calculated.

    >roup f unc tions cannot be used in the ,HE!E clause.

    $ou can create super aggregates usingthe C5#E and !))5; modifiers in the>!5; #$ clause.

    ExamEssentials

    Understand the usage of D6S6$C in group functions. ,hen

    "9(T9NCT is specified- onl% one of each non.N5)) value is applied to the

    function. To appl% all non.N5)) values- the 'e% word &)) should be used.

     COUNT

    COUNT(expr) returns the number of rows with non-null values for the expr.COUNT(DISTINCT expr) returns the number of istin!t non-null values of the expr.

    S"#"CT COUNT(DISTINCT epartment$i)%&O' emploees

    Know where group functions can #e used. >roup functions can be used in

    >!5; #$- !"E! #$-and H&=9N> clauses.The% cannot be used in ,HE!E

    clauses.

    ;age ( of '(

  • 8/16/2019 Oracle Exams1z0 051

    8/17

    ExamEssentials N

    Know how 76$ and 7"8 sort date and character data. lder dates

    evaluate to lower values- while newer dates evaluate to higher values.

    Character data- even if it contains numbers- is sorted according to the

     N)(/(!T s pecification.

    Know which e2pressions in a SELEC list !ust appear in a 5ROU9 BYclause. 9f an% gr ouping is performed- all non group function expressions

    and non constant expressions must appear in the >!5; #$ clause.

    Know the order of precedence for e%aluating nested functions. $ou

    ma% need to evaluate an expression containing nested functions. +a'e

    sure %ou understand the lef ttor ight order of precedence used to evaluate

    these expr essions.

    ;age : of '(

  • 8/16/2019 Oracle Exams1z0 051

    9/17

    ExamEssentials N

    CH Displaying Data fro! 7ultiple a#les

    9f the 2oin condition uses the equalit% operator  BF or 9ND-it is 'nown as an

    equalit% 2oin. 9f an% other operator is used to 2oin the tables- it is a non

    equalit% 2oin. 9f %ou do not s pecif% an% 2oin condition between the tables-the

    result will be a Cartesian productG each row f r om the first table 2oined to

    ever% row in the second table. To avoid Cartesian 2oins- there should be at

    least n-12oin conditions in the ,HE!E clause when there are n tables in the

    *!+ clause. & table can be 2oined to itself. 9f %ou want to select the results

    from a table- even if ther e are no corresponding rows in the 2oined table- %ou

    can use the outer 2oin operatorG

    & sub quer% is a quer% within a quer%. ,riting sub queries is a powerful

    wa% to mani pulate data. $ou can write singlerow and multiplerow

    subqueries. (inglerow sub queries must return 7ero or one row4 multiplerow sub queries return 7ero or more rows.9N and EH9(T( are the most

    commonl% used sub quer% operators. (ub queries can appear in the ,HE!E

    clause or in the *!+ clause. The% can also replace table names in (E)ECT-

    "E)ETE- 9N(E!T- and 5;"&TE statements. (ubqueries that return one row

    and one column result ar e 'nown as scalar sub queries. (calar sub queries

    can be used in most places where %ou would use an expr ession.

    ExamEssentials

    Understand  ;oins. +a'e sure %ou 'now the different t%pes of 2oins.

    5nderstand the differ ence between natural- cross- simple- complex- and

    outer 2oins.

    Be sure of the ;oin synta2. (pend time practicing each t%pe of 2oin using

    the &N(9 s%ntax. 5nderstand the restrictions of using each &N(9 'e%word

    in the I9N and their im plied columnnaming conventions

    ;age

  • 8/16/2019 Oracle Exams1z0 051

    10/17

    ExamEssentials N

    C1 3 Using Su#&ueries to Sol%e =ueries

      Know how to write su# &ueries. 5nderstand the use and flexibilit% of sub

    queries. ;r actice using scalar sub queries and correlated sub queries.

    Understand the use of the ORDER BY clause in the su# &ueries. $ou can

    use the !"E! #$ clause in all sub queries- except the sub queries

    appearing in the ,HE!E clause of the quer %. $ou can use the >!5; #$

    clause in the sub queries.

    C1 4 SE O9ER"ORS

    Know the set operators. 5nderstand the set operators that can be

    used in com pound queries. Know the difference between the 5N9N and

    5N9N &)) oper ator s.

    Understand where you can specify the ORDER BY clause when using set

    operators. ,hen using set operators to 2oin two or more queries- the

    !"E! #$ clause can appear onl% at the ver% end of the quer%. $ou can

    specif% the column names as the% appear in the top quer% or use positional

    notation.

    ;age '> of '(

  • 8/16/2019 Oracle Exams1z0 051

    11/17

    ExamEssentials N

    CH J  7anipulating Data

    Know the synta2 for the 6$SER state!ent. ,hen a subquer% is used

    to add rows to a table- the =&)5E( clause should not be used.

    9ractice U9D"E state!ents The 5;"&TE statement can update multiple

    columns in the same row using a subquer%. +ultiple subqueries can also

     be used to update columns in a single r ow.

    Understand what will #egin and end a transaction. & transaction will

     begin with an 9N(E!T- 5;"&TE- "E)ETE- +E!>E- or (E)ECT *! 5;"&TE

    statement. & C++9T or !))#&CK will end a transaction. & "")

    statement can also end a tr ansaction.

    Know how to set and roll #ac- to sa%e points. (avepoints are set with

    the (&=E;9NT statement. "ata changes made after a savepoint are undone

    when a !))#&CK T (&=E;9NT statement is executed. !))#&CK T

    (&=E;9NT is a partial undo oper ation.

    Understand the scope of data changes and consistency. (tatement level

    consistenc% is automatic and will ensure that each (E)ECT will see an image

    of the database consistent with the beginning of the statements execution.

    Transactionlevel consistenc% will ensur e that all (E)ECT statements within

    a transaction will see an image of the database consistent with the

     beginning of the tr ansaction

    .

    ;age '' of '(

  • 8/16/2019 Oracle Exams1z0 051

    12/17

    ExamEssentials N

    CH L Using DDL State!ents to Create and 7anage a#les

    Understand data types. Know each data t% pes limitations and

    accepted values. Concentrate on the new T9+E(T&+; and 9NTE!=&)

    datat% pes.Know how date arith!etic wor-s. Know the resulting data t%pe of date

    arithmetic- es peciall% between 9NTE!=&) and "&TE datat% pes.

    Know how to !odify colu!n characteristics. 5nderstand how to change

    data t%pes- add and modif% constraints- and ma'e other modifications.

    Understand the rules associated with changing data type definitions of

    colu!ns with rows in a ta#le. ,hen the table is not empt%- %ou can change

    a datat%pe onl% from CH&! to =&!CH&!

  • 8/16/2019 Oracle Exams1z0 051

    13/17

    ExamEssentials N

    Know how a constraint can #e defined. $ou can use the C!E&TE T)E or

    &)TE! T)E statement to define a constraint on the ta ble.

    ;age ' of '(

  • 8/16/2019 Oracle Exams1z0 051

    14/17

    ExamEssentials N

    Ch < Creating Other Sche!a O#;ects

    Understand how ;oin %iews wor-. Know the restrictions on the

    columns that can be updated in a 2oin view.

    Understand how constraints are used with %iews. 5nderstand the t%pe

    of constraints that can be defined on a ta ble.

    Understand how in line %iews are used. 9n line views are subqueries

    used in the *!+ clause. These subqueries can have an !"E! #$ clause.

    Know how to change the definition of a %iew. The C!E&TE ! !E;)&CE

    =9E, statement is used to change the definition of the view. The &)TE! =9E,

    statement is used to recompile a view or to manage constraints on a view.

    Know the precise synta2 for o#taining se&uence %alues. $ou should

    understand how  to use  sequence _name.  NET=&) and

     sequence _name. C5!!=&) to obtain the next and most recentl%

    generated number from a sequence.

    ;age '0 of '(

  • 8/16/2019 Oracle Exams1z0 051

    15/17

    ExamEssentials N

    Understand when inde2es degrade perfor!ance.EX4%A5AT5O

    • An index creates an entry for each value that appears in the indexed columns.  #y default Oracle creates #6tree indexes

    • #itmap and #6Tree index maps column&$0 data to RO752

    • 1etches a ro8 by usin9 RO752 instead of a full table scan.

    • 5ndexes improve $E%ECT !42ATE A2 2E%ETE operations.

    • An index can be used is a leadin9 subset of the indexed column appears in the

    $E%ECT or 7HERE clause.

    Know that indexes degrade the per f or mance of "+) operationsB9N(E!T-

    5;"&TE- and "E)ETED.

    &utomaticall%G & unique index is created automaticall% when %ou define a;!9+&!$ KE$ or 5N985E constraint in a table definition.

    ;age '3 of '(

  • 8/16/2019 Oracle Exams1z0 051

    16/17

    ExamEssentials N

    B-Tree Index6$uited for hi9h cardinality columns (columns a!in" man# distinct !alues$

    6Excels at servicin9 simple :ueries& not havin9 many OR ; A2 statements0

    Bitmap Index

    6$uited for hi9h cardinality columns male9N and >EN"E! -are all lowcardinalit% columns. There

    are onl% three possible values for marital status and region and two possible values forgender 

    %unction-Based Indexes.• A function6based index is an index based on expressions.

    • The index expression is built from table columns constants $=% functions

    and user6defined functions.

    &RE'TE INE) *it &RE'TE T'B+E ,tatement

    CREATE TA#%E E7_E"4&employee_id !"#ER&>0  4R5"AR? @E? !$5 52EX

    ;age '4 of '(

  • 8/16/2019 Oracle Exams1z0 051

    17/17

    ExamEssentials N

      &CREATE 52EX emp_id_idx O  E7_E"4&employee_id00first_name BARCHAR*&*+0last_name BARCHAR*&*00D

    $E%ECT 52EX_A"E TA#%E_A"E1RO" !$ER_52EXE$

    7HERE TA#%E_A"E 3 'E7_E"4'D

    Know when a #it!ap inde2 is !ore appropriate than a B)treeinde2.

    #itmap indexes

    ,or' best on lowto medium cardinalit% columns where rowlevel loc'ing is

    not needed. 9n contrast- #tree indexes wor' best on highto medium

    cardinalit% columns and do suppor t rowlevel loc' ing.

    Know how Oracle will resol%e ta#le references. racle will first search for 

    a table or view that matches the referenced name. 9f no table or view is

    found- private s%non%ms are then examined. *inall%- public s%non%ms are

    examined. 9f no matching name is found- r acle will raise an exce ption.

    'lterin" seuences &solution for the above pitfalls0

    ote ?ou cannot directly alter the se:uence and chan9e its EXTBA%. 5nstead youcan taFe one of the follo8in9 approaches

    • 2rop and re6create it&invalidatin9 all dependent obGects and losin9 the 9rants0.

    • $elect EXTBA% from it enou9h times to brin9 the se:uence up to a desired value.• Alter the se:uence by chan9in9 the 5CRE"ET #? value to a lar9e number select

    EXTBA% from the se:uence to maFe it increment by the lar9e number then alterthe 5CRE"ET #? value bacF do8n to the ori9inal small value.

    ;age '( of '(