Sei sulla pagina 1di 5

Oracle8 DBA:SQL and PL/SQL

Oracle8 DBA: SQL and PL/SQL - CramNotes

SQL COMMANDS

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


● DDL (Data Definition Language) consists of commands used to define or alter
database internal structures such as tables, views, indexes, and so on. DDL
commands include CREATE, ALTER, DROP, and TRUNCATE.
● DCL (Data Control Language) consists of commands used to control data
access, such as the several forms of the GRANT command.
● DML (Data Manipulation Language) consists of commands used to populate or
alter database data contents. DML commands include INSERT, UPDATE,
DELETE, and SELECT.
● SQL has intrinsic functions that allow for data type conversion and data
manipulation.
● SQL has operators that define operations between values and expressions.
● SELECT statements make use of joins, which can be one of the following
types:
❍ Equijoins—State equality or inequality operations.
❍ Outer joins—Used when one of the tables is deficient in data to complete
the specified relationships.
Self-joins—Used when a table is joined to itself by use of table aliases.

● SQL supports SORT, COLLECTION, and SET operations.

PRECEDENCE OF OPERATORS
● The precedence of operators are as follows:
❍ (+) and (-)—Unary operators (positive and negative number indicators)
and the PRIOR operators.
❍ (*) and (/)—Multiplication and division operators.
❍ Binary (=)—Arithmetic operators (such as addition “+” and subtraction
“-“) and the concatenation operator (||).
All comparison operators—This includes the NOT, AND, and OR logical

operators.
● Parentheses always override precedence. Operators inside parentheses are
always evaluated first.
FUNCTIONS
● Functions are either scalar (single row) or aggregate (group) in nature. A
single-row function returns a single result row for each row of a queried table
or view, whereas an aggregate function returns a single value for a group of
rows.
● A single-value function can appear in a SELECT if the SELECT doesn’t contain
a GROUP BY clause. Single-value functions can also appear in WHERE,
START with, and CONNECT By clauses. Single-row functions can also be
nested.

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


Oracle8 DBA:SQL and PL/SQL

LIMITS ON A VIEW
● A view can’t be updated if:
❍ It has a join.
❍ It uses SET operator.
❍ It contains a GROUP BY clause.
❍ It uses any group function.
❍ It uses a DISTINCT operator.
❍ It has flattened subqueries.
❍ It uses nested table columns.
❍ It uses CAST and MULTISET expressions.

DELETE AND TRUNCATE COMMANDS


● The DELETE command is used to remove some or all rows from a table
allowing ROLLBACK of the command if no COMMIT is executed.
● The TRUNCATE command is used to remove all rows from a table, and no
ROLLBACK is allowed.
OUTER JOINS
● The restrictions on outer joins are:
❍ The (+) operator can appear only in the WHERE clause and can apply
only to a table or view.
❍ If there are multiple join conditions, the (+) operator must be used in all
of these conditions.
❍ 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.
❍ A condition containing a column with a (+) cannot be OR related to
another condition; neither can it be used in an IN condition.
❍ A column marked with the (+) operator cannot be compared to a
subquery.
❍ Only one table in a multitable join can have the (+) operator applied to
its joins to one other table.
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.
❍ Use the MODIFY clause to increase the size of columns or to change the
precision of numeric columns.
❍ Use the MODIFY clause to change columns with all null values so that
the columns are shorter or have a different data type.
❍ Alter the PCTREE, PCTUSED, INITRANS, or MAXTRANS values for
any table.
❍ Use the STORAGE clause to alter the storage parameters for any table.
❍ Use the PARALLEL clause to change or remove the parallelism of a
table.
❍ Use CACHE or NONCACHE to specify whether a table is to be cached or
not.

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


Oracle8 DBA:SQL and PL/SQL

❍ Use the DROP clause to remove a constraint.


❍ Use the DEFAULT value clause to add a default value to any column.
❍ Use the DISABLE clause to disable a constraint. (This is the only way to
disable a constraint.) When the CASCADE option is specified with
DISABLE, it also disables all dependent integrity constraints.
❍ Use the DEALLOCATE UNUSED clause to deallocate space that is not
being used. (You can use the KEEP option to specify a safety margin
above the high-water mark.)
❍ Use the ENABLE clause to enable a constraint that was created as
disabled. (The ENABLE clause can be used only in CREATE and ALTER
TABLE commands.)
❍Use the ADD CONSTRAINT clause to add a primary, not null, check, or
foreign key constraint to an existing table.
● The things you can’t do with the ALTER TABLE command include:
❍ Modify a column that has values to be shorter or to be a different data
type than it already is.
❍ Add a NOT NULL column to a table that has rows in a single step
operation with only the ALTER TABLE command.
❍ Alter a column to NOT NULL if it has rows with null values in that
column.
❍ Rename a column.
❍ Drop a column.
❍ Change a column’s data type to an incompatible data tyoe.
DATA DICTIONARY
● At its lowest level, the data dictionary consists of X$ and K$ C structs, not
normally viewable or used by DBA.
● The data dictionary has V$ virtual views or tables, which contain variable data
such as statistics.
● The data dictionary has dollar ($) tables, which actually contain database
metadata about tables, views, indexes and other database structures.
● At the uppermost layer, the data dictionary has DBA_ views about all the
objects, ALL_ views about all objects a user can access, and USER_ views
about all objects a user owns.
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 procedural
statements and passes the SQL statements to the SQL server.
● A PL/SQL procedure may return one or more values. It is used to perform
many functions, such as table input, table output, and value processing.
● A PL/SQL function must return one and only one value and cannot be used to
perform input and output. A function should be used only to manipulate
existing data; this ties in with the concept of function purity.
● A procedure consists of header, declarative, and executable (which may
contain an exception handling block) sections.
● An anonymous PL/SQL block is an externally stored PL/SQL block that is not
named and contains at a minimum an executable block. It may, however,

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


Oracle8 DBA:SQL and PL/SQL

contain a declarative and executable (with or without exception handling


block) section. An anonymous PL/SQL block can be called from any Oracle
environment. An anonymous PL/SQL block is used to form the heart of table
triggers.
● To process SELECT commands, PL/SQL uses either an explicit cursor (which
usually returns more than one row) or an implicit cursor (which can return
only one row or an exception will be raised).
● Flow control in PL/SQL uses loops, which can be counted FOR loops,
conditional WHILE loops, or conditional infinite loops.
● Conditional flow control uses the IF…THEN…ELSE construct in PL/SQL.
● Multiple IF constructs can be nested using the IF…ELSIF construct.
● The GOTO is used for unconditional branching in PL/SQL.
● The NULL command is a special command in PL/SQL used to fulfill the
requirement for a flow control command to be followed by an executable
command. Although NULL is an executable command, it does nothing.
● SQL in the form of DML can be used in PL/SQL. Generally speaking, without
using specially provided procedure packages, DDL cannot be used in PL/SQL.
● COMMIT is used in PL/SQL to commit changed data explicitly.
● ROLLBACK is used in PL/SQL to return altered data to its previous state.

USERS AND GRANTS


● Users can be created, altered, and dropped using the CREATE, ALTER, and
DROP commands.
● Users are granted profiles, roles, and privileges.
● Profiles are used to limit resource usage and can be used to enforce password
limitations.
● Roles are used to group a collection of privileges, roles, and grants that can
then be granted en masse to a user or another role.
● Grants and privileges are given at he system table, or column level.
● Special roles such as OSOPER, OSDBA, CONNECT, RESOURCE, and DBA
are automatically created:
❍ OSOPER—Grants all rights except the ability to create a database.
❍ OSDBA—Grants OSOPER and the right to create databases.
❍ CONNECT—Grants a basic set of privileges.
❍ RESOURCE—Grants a set of privileges that specifically apply to a
developer.
❍ DBA—Grants almost unlimited rights that a DBA would use.

DATABASE DESIGN
● The five-step system development cycle consists of:
❍ Strategy and analysis—Users are interviewed and requirements are
generated. Design documents are written. Entities, attributes, and
relationships are identified as well as relationships.
❍ Design—The actual system is designed in detail. Entity relationship
diagrams (ERDs), function decompositions, and data flow diagrams are
created. In object-oriented design, Universal Modeling Language (UML)
diagrams may be used instead of ERDs.

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


Oracle8 DBA:SQL and PL/SQL

❍ Build and Document—The system is built mapping the ERD to tables and
columns (or objects) and relationships to primary key and foreign key
relationships (or REF values). The function decompositions and data
flows are used to create forms, reports, and other application modules.
❍ Transition—The system is moved from development into production.
During this period, user acceptance testing is performed and final
documentation is generated.
❍ Production—The system is placed into production, code is locked down,
and a firm change control process is implemented. This is the final
stage.
● Entities (or objects) can be either parent, or child, dependent, or independent.
An entity (or object) is a thing of importance.
● Relationships (or REFs) are named associations between things of significance
and have cardinality and optionality. Relationships can be one-to-one,
one-to-many, or even many-to-many, although most should be either required
or optional one-to-manys. A REF can be only a one-one relationship from child
back to parent record.
● Normalization is the process where repeating values (attributes) are removed
from an entity until all attributes in the entity relate only to the entity’s unique
identifier. The most common form of normalization is third normal form.

This CramNotes is provided by Coriolis. To read further details on this subject we suggest you to
consider purchasing the book below.

Oracle8 DBA: SQL and PL/SQL Exam Cram


by Michael R. Ault, Michael L. Ault (Paperback)
Average Customer Review:
Usually ships in 24 hours

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

Potrebbero piacerti anche