Oracle 8 - SQL and PLSQL CramNotes

Embed Size (px)

Citation preview

  • 8/8/2019 Oracle 8 - SQL and PLSQL CramNotes

    1/5

    racle8 DBA: SQL and PL/ SQL - CramNotes

    QL COMMANDS

    SQL consists of DDL, DCL, and DML statements.q

    DDL (Data Definition Language) consists of commands used to define or alter

    database internal structures such as tables, views, indexes, and so on. DDLcommands include CREATE, ALTER, DROP , and TRUNCATE.

    q

    DCL (Data Control Language) consists of commands used to control dataaccess, such as the several forms of the GRANT command.

    q

    DML (Data Manipulation Language) consists of commands used to populate oralter database data contents. DML commands include INSERT, UPDATE,DELETE, and SELECT.

    q

    SQL has intrinsic functions that allow for data type conversion and datamanipulation.

    q

    SQL has operators that define operations between values and expressions.q

    SELECT statements make use of joins, which can be one of the followingtypes:

    EquijoinsState equality or inequality operations.r

    OuterjoinsUsed when one of the tables is deficient in data to completethe specified relationships.

    r

    Self-joinsUsed when a table is joined to itself by use of table aliases.r

    q

    SQL supports SORT, COLLECTION, and SET operations.q

    PRECEDENCE OF OPERATORS

    The precedence of operators are as follows:

    (+) and (-)Unary operators (positive and negative number indicators)and the PRIOR operators.

    r

    (*) and (/)Multiplication and division operators.r

    Binary (=)Arithmetic operators (such as addition + and subtraction-) and the concatenation operator (||).

    r

    All comparison operatorsThis includes the NOT, AND, and OR logicaloperators.

    r

    q

    Parentheses always override precedence. Operators inside parentheses arealways evaluated first.

    q

    FUNCTIONSFunctions are either scalar (single row) or aggregate (group) in nature. Asingle-row function returns a single result row for each row of a queried tableor view, whereas an aggregate function returns a single value for a group ofrows.

    q

    A single-value function can appear in a SELECT if the SELECT doesnt containa GROUP BY clause. Single-value functions can also appear in WHERE,START w ith, and CONNECT By clauses. Single-row functions can also benested.

    q

    Oracle8 DBA:SQL and PL/SQL

    le:///C|/Work/PDF/sql_and_pl.htm (1 of 5) [2/26/2001 3:18:43 PM]

  • 8/8/2019 Oracle 8 - SQL and PLSQL CramNotes

    2/5

    LIMITS ON A VIEW

    A view cant be updated if:

    It has a join.r

    It uses SET operator.r

    It contains a GROUP BY clause.r

    It uses any group function.r

    It uses a DISTINCT operator.r

    It has flattened subqueries.r

    It uses nested table columns.r

    It uses CAST and MULTISET expressions.r

    q

    DELETE AND TRUNCATE COMMANDS

    The DELETE command is used to remove some or all rows from a tableallowing ROLLBACK of the command if no COMMIT is executed.

    q

    The TRUNCATE command is used to remove all rows from a table, and noROLLBACK is allowed.

    q

    OUTER JOINSThe restrictions on outer joins are:

    The (+) operator can appear only in the WHERE clause and can applyonly to a table or view.

    r

    If there are multiple join conditions, the (+) operator must be used in allof these conditions.

    r

    The (+) operator can be applied to a column only, not to an expression.However, it can be applied to a column inside an arbitrary expression.

    r

    A condition containing a column with a (+) cannot be OR related toanother condition; neither can it be used in an IN condition.

    r

    A column marked with the (+) operator cannot be compared to asubquery.

    r

    Only one table in a multitable join can have the (+) operator applied toits joins to one other table.

    r

    q

    THE ALTER TABLE COMMAND

    The following are things you can do with the ALTER TABLE command:

    Use the ADD clause to add columns that have null values to any table.r

    Use the MODIFY clause to increase the size of columns or to change theprecision of numeric columns.

    r

    Use the MODIFY clause to change columns with all null values so thatthe columns are shorter or have a different data type.

    r

    Alter the PCTREE, PCTUSED, IN ITRANS, or MAXTRANS values forany table.

    r

    Use the STORAGE clause to alter the storage parameters for any table.r

    Use the PARALLEL clause to change or remove the parallelism of atable.

    r

    Use CACHE or NONCACHE to specify whether a table is to be cached ornot.

    r

    q

    Oracle8 DBA:SQL and PL/SQL

    le:///C|/Work/PDF/sql_and_pl.htm (2 of 5) [2/26/2001 3:18:43 PM]

  • 8/8/2019 Oracle 8 - SQL and PLSQL CramNotes

    3/5

    Use the DROP clause to remove a constraint.r

    Use the DEFAULT value clause to add a default value to any column.r

    Use the DISABLE clause to disable a constraint. (This is the only way todisable a constraint.) When the CASCADE option is specified withDISABLE, it also disables all dependent integrity constraints.

    r

    Use the DEALLOCATE UNUSED clause to deallocate space that is notbeing used. (You can use the KEEP option to specify a safety marginabove the high-water mark.)

    r

    Use the ENABLE clause to enable a constraint that was created asdisabled. (The ENABLE clause can be used only in CREATE and ALTERTABLE commands.)

    r

    Use the ADD CONSTRAINT clause to add a primary, not null, check, orforeign key constraint to an existing table.

    r

    The things you cant do with the ALTER TABLE command include:

    Modify a column that has values to be shorter or to be a different datatype than it already is.

    r

    Add a NOT NULL column to a table that has rows in a single stepoperation with only the ALTER TABLE command.

    r

    Alter a column to NOT NULL if it has rows with null values in thatcolumn.

    r

    Rename a column.r

    Drop a column.r

    Change a columns data type to an incompatible data tyoe.r

    q

    DATA DICTIONARY

    At its lowest level, the data dictionary consists ofX$ and K$ C structs, notnormally viewable or used by DBA.

    q

    The data dictionary has V$ virtual views or tables, which contain variable data

    such as statistics.

    q

    The data dictionary has dollar ($) tables, which actually contain databasemetadata about tables, views, indexes and other database structures.

    q

    At the uppermost layer, the data dictionary has DBA_ views about all theobjects, ALL_ views about all objects a user can access, and USER_ viewsabout all objects a user owns.

    q

    PL/ SQL

    PL/SQL consists of the PL/SQL engine, which can be incorporated in the forms,SQL*Plus, or reports executables. The PL/SQL engine processes proceduralstatements and passes the SQL statements to the SQL server.

    q

    A PL/SQL procedure may return one or more values. It is used to performmany functions, such as table input, table output, and value processing.

    q

    A PL/SQL function must return one and only one value and cannot be used toperform input and output. A function should be used only to manipulateexisting data; this ties in with the concept of function purity.

    q

    A procedure consists of header, declarative, and executable (which maycontain an exception handling block) sections.

    q

    An anonymous PL/SQL block is an externally stored PL/SQL block that is notnamed and contains at a minimum an executable block. It may, however,

    q

    Oracle8 DBA:SQL and PL/SQL

    le:///C|/Work/PDF/sql_and_pl.htm (3 of 5) [2/26/2001 3:18:43 PM]

  • 8/8/2019 Oracle 8 - SQL and PLSQL CramNotes

    4/5

    contain a declarative and executable (with or without exception handlingblock) section. An anonymous PL/SQL block can be called from any Oracleenvironment. An anonymous PL/SQL block is used to form the heart of tabletriggers.

    To process SELECT commands, PL/SQL uses either an explicit cursor (whichusually returns more than one row) or an implicit cursor (which can returnonly one row or an exception will be raised).

    q

    Flow control in PL/SQL uses loops, which can be counted FOR loops,conditional WHILE loops, or conditional infinite loops.

    q

    Conditional flow control uses the IF THEN ELSE construct in PL/SQL.q

    Multiple IF constructs can be nested using the IFELSIF construct.q

    The GOTO is used for unconditional branching in PL/SQL.q

    The NULL command is a special command in PL/SQL used to fulfill therequirement for a flow control command to be followed by an executablecommand. Although NULL is an executable command, it does nothing.

    q

    SQL in the form of DML can be used in PL/SQL. Generally speaking, withoutusing specially provided procedure packages, DDL cannot be used in PL/SQL.

    q

    COMMIT is used in PL/SQL to commit changed data explicitly.q

    ROLLBACK is used in PL/SQL to return altered data to its previous state.q

    USERS AND GRANTS

    Users can be created, altered, and dropped using the CREATE, ALTER, andDROP commands.

    q

    Users are granted profiles, roles, and privileges.q

    Profiles are used to limit resource usage and can be used to enforce passwordlimitations.

    q

    Roles are used to group a collection of privileges, roles, and grants that canthen be granted en masse to a user or another role.

    q

    Grants and privileges are given at he system table, or column level.q

    Special roles such as OSOPER, OSDBA, CONNECT, RESOURCE, and DBAare automatically created:

    OSOPERGrants all rights except the ability to create a database.r

    OSDBAGrants OSOPER and the right to create databases.r

    CONNECTGrants a basic set of privileges.r

    RESOURCEGrants a set of privileges that specifically apply to adeveloper.

    r

    DBAGrants almost unlimited rights that a DBA would use.r

    q

    DATABASE DESIGN

    The five-step system development cycle consists of:

    Strategy and analysisUsers are interviewed and requirements aregenerated. Design documents are written. Entities, attributes, andrelationships are identified as well as relationships.

    r

    DesignThe actual system is designed in detail. Entity relationshipdiagrams (ERDs), function decompositions, and data flow diagrams arecreated. In object-oriented design, Universal Modeling Language (UML)diagrams may be used instead of ERDs.

    r

    q

    Oracle8 DBA:SQL and PL/SQL

    le:///C|/Work/PDF/sql_and_pl.htm (4 of 5) [2/26/2001 3:18:43 PM]

  • 8/8/2019 Oracle 8 - SQL and PLSQL CramNotes

    5/5

    Build and DocumentThe system is built mapping the ERD to tables andcolumns (or objects) and relationships to primary key and foreign keyrelationships (or REF values). The function decompositions and dataflows are used to create forms, reports, and other application modules.

    r

    TransitionThe system is moved from development into production.During this period, user acceptance testing is performed and finaldocumentation is generated.

    r

    ProductionThe system is placed into production, code is locked down,and a firm change control process is implemented. This is the final

    stage.

    r

    Entities (or objects) can be either parent, or child, dependent, or independent.An entity (or object) is a thing of importance.

    q

    Relationships (or REFs) are named associations between things of significanceand have cardinality and optionality. Relationships can be one-to-one,one-to-many, or even many-to-many, although most should be either requiredor optional one-to-manys. A REF can be only a one-one relationship from childback to parent record.

    q

    Normalization is the process where repeating values (attributes) are removedfrom an entity until all attributes in the entity relate only to the entitys unique

    identifier. The most common form of normalization is third normal form.

    q

    This CramNotes is provided by Coriolis. To read further details on this subject we suggest you to

    onsider purchasing the book below.

    Oracle8 DBA: SQL and PL/SQL Exam Cramby Michael R. Ault, Michael L. Ault (Paperback)

    Average Customer Review:Usually ships in 24 hours

    Oracle8 DBA:SQL and PL/SQL

    l ///C|/W k/PDF/ l d l ht (5 f 5) [2/26/2001 3 18 43 PM]

    http://www.amazon.com/exec/obidos/ASIN/1576105776/dumpsitehttp://www.amazon.com/exec/obidos/ASIN/1576105776/dumpsitehttp://www.amazon.com/exec/obidos/ASIN/1576105776/dumpsite