Professional Documents
Culture Documents
p
| |
Relational databases are powerful because they require few assumptions about how
data is related or how it will be extracted from the database. As a result, the same
database can be viewed in many different ways.
Almost all full-scale database systems are RDBMS's. Small database systems,
however, use other designs that provide less flexibility in posing queries. RDBMS
data is structured in database tables, fields and records. Each RDBMS table
consists of database table rows.
Each database table row consists of one or more database table fields. RDBMS
store the data into collection of tables, which might be related by common fields
(database table columns).
RDBMS also provide relational operators to manipulate the data stored into the
database tables. Most RDBMS use SQL as database query language.
Edgar Codd introduced the relational database model.
Many modern DBMS do not conform to the Codd¶s definition of a RDBMS, but
nonetheless they are still considered to be RDBMS. The most popular RDBMS are
MS SQL Server, DB2, Oracle and MySQL.
Oracle Database is the first database designed for enterprise grid computing, the
most flexible and cost effective way to manage information and applications.
Enterprise grid computing creates large pools of industry-standard, modular
storage and servers. With this architecture, each new system can be rapidly
provisioned from the pool of components. There is no need for peak workloads,
because capacity can be easily added or reallocated from the resource pools as
needed.
Oracle database management tracks its computer data storage with the help of
information stored in the SYSTEM table space. The SYSTEM tablespace contains
the data dictionary ² and often (by default) indexes and clusters. (A data
dictionary consists of a special collection of tables that contains information about
all user-objects in the database). Since version 8i, the Oracle RDBMS also
supports "locally managed" tablespaces which can store space management
information in bitmaps in their own headers rather than in the SYSTEM tablespace
(as happens with the default "dictionary-managed" tablespaces).
If the Oracle database administrator has instituted Oracle RAC (Real Application
Clusters), then multiple instances, usually on different servers, attach to a central
storage array. This scenario offers numerous advantages, most importantly
performance, scalability and redundancy. However, support becomes more
complex, and many sites do not use RAC. In version 10g, grid computing has
introduced shared resources where an instance can use (for example) CPU
resources from another node (computer) in the grid.
The Oracle DBMS can store and execute stored procedures and functions within
itself. PL/SQL (Oracle Corporation's proprietary procedural extension to SQL), or
the object-oriented language Java can invoke such code objects and/or provide the
programming structures for writing them.
!
1 There is no relationship concept. It is use to establish relationship
concept between two database objects
i.e. tables.
2 It support single user. It support multiuser.
3 It reads data as files internally. It reads tables internally.
4 It requires low software and It requires high software and hardware
hardware requirements. requirements.
5 It is less secure. It is more secure.
6 It is possible to store and retrieve It is possible to store and retrieve large
fewer amounts of data in it. amount of data in it.
7 No keys are used. Keys are used.
8 Normalization concept is not Normalization is present.
present.
9 Used for smaller organizations Large organizations where large
where security is not major amount data is maintain and security is
concern. also important.
10 No data integrity. Data integrity concept is present.
11 It does not support null values. Support null values.
12 Examples: FoxPro Examples: SQL Server
MS-Access Oracle
"
A data type is a set of data with values having predefined characteristics. Each
language has its own data types. Usually, a limited number of such data types
come built into a language. The language usually specifies the range of values for a
given data type, how the values are processed by the computer, and how they are
stored. Some data types in SQL are: char, number, date etc.
The various Data Types along with their description are shown below:
c
p
c
p
With CREATE TABLE, a new table can be created. A table can be considered as
a basic structure within which data is stored. It consists of rows and columns. A
row represents a single record while a column represents attributes/fields which
can be thought of as one of the components contributing to make a record. While
creating a table, data types have to be mentioned for each field.
'
This statement is used to view data from the table.
'&To select all the column from the table:select * from studentcse;
)
Distinct keyword is used to retrieve values that are distinct or non-repetitive. The
SQL Select retrieves values from database table which may be repetitive. Adding
the word Distinct to Select, we can get rid of this problem.
c
p
c
p
Sorting is an important feature of any database. We can arrange data according to
the sequence we need to put them into.
ORDER BY is used to get the result in the sorted manner. Unless Explicitly stated,
the order by clause sorts the result in ascending order.
'
'&delete from studentcse where name like '__n%';
If the user want to delete a table (the table structure, attributes, and indexes will
also be deleted) Permanently then drop command can be used for the purpose.
Truncate command is used to simply get rid of the data but not the table itself.
'$
Update statement is used to edit or update data in the table. Once there's data in the
table, we might find that there is a need to modify the data. To do so, we can use
the UPDATE command.
'& update studentcse set marks=marks+10 where rollno>205 and name like
'Anish';
&
&
Once a table is created in the database, there are many occasions where one may
wish to change the structure of the table. ALTER TABLE is basically used to
- Add a column
- Drop a column
- Change a column name
- Change the data type for a column
"
Column Alias are used to rename a table¶s columns for the purpose of a particular
query.
'&""$"$á
&
&
This command is used to describe the structure of the the structure of the table.
%&describe tablename;
'&describe emp2;
The various Operators along with their description are shown below in tabular
form:
Operator Description
= Equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<> Not equal to
LIKE String comparison test
AND Logical And returns TRUE when both the specified conditions are true
OR Logical Or returns TRUE when atleast one of the specified conditions is
true
NOT Logical Not returns TRUE when none one of the specified conditions is
true
'&select * from studentcse where marks>300;
select ename from employee where ecity like 'APS' AND ecode IN(select ecode
from company where desg like 'Manager');
The BETWEEN keyword is used to test whether or not a value is present between
the two values mentioned in the query followed by the keyword BETWEEN.
./ | . ""/&
./ 2. %""/&
./
./&
It returns the absolute value of any numeric data. It can also be applied on dual
table.
./
'.
3/
./( &
.1/ &
.1/&
It shows the specified number of digits after truncating the other digits after
decimal.
.1/ &
This function returns the remainder provided two numbers dividend and divisor.
.1/**&
.%/ |*&
It returns the immediate greater integer value of the given decimal value.
ÿÿ
| -* |
&
There are various functions in SQL that can be applied on the string type data.
./
||&
It returns the decimal representation in the database character set of the first
character of string.
./ &
./( &
What this function does is that it fills up the extra space in the field with the
padding either from the left or from the right.
(i) 4&
./4 "&
./4&
GROUP BY... was added to SQL because aggregate functions (like SUM) return
the aggregate of all column values every time they are called, and without the
GROUP BY function it was impossible to find the sum for each individual group
of column values.
c
p
c
p
60| -
&
HAVING... was added to SQL because the WHERE keyword could not be used
against aggregate functions (like SUM), and without HAVING... it would be
impossible to test for result conditions.
c
p
c
p
X|
&
Sometimes we have to select data from two or more tables to make our result
complete. We have to perform a join.
The INNER JOIN returns all rows from both tables where there is a match. If there
are rows in Employees that do not have matches in Orders, those rows will not be
listed.
ÿÿX&
Outer join uses two tables to extract the data .It displays all the rows of first table
or second table or both depending on left outer join ,right outer join or full outer
join.
½p * X|
%& SELECT <cloumn1>, <column2>, <column3> FROM <first_table>
LEFT JOIN second_table ON <first_table.keyfield> =
<second_table.keyfield>;
%& SELECT <cloumn1>, <column2>, <column3> FROM
<first_table>RIGHT JOIN second_table ON <first_table.keyfield> =
<second_table.keyfield>;
%& SELECT <cloumn1>, <column2>, <column3>FROM
<first_table>FULL JOIN second_table ON <first_table.keyfield> =
<second_table.keyfield>;
----|
&It select the common tuples in both the tables.
a.p Unique constraint
b.p Primary key constraint
c.p Default constraint
d.p Check constraint
!p 3 & This constraint ensures that no two rows have same
value in the specified column(s). Example
!p ",&This declares a column as the primary key of the
table. It is similar to default constraint except that only one column can be
specified as primary key. Example
!p &A default value can be specified for a column using the
DEFAULT clause. When a user does not enter value for the column (having
default value), automatically the defined default value inserted in the field.
!p , & This constraint limits values that can be inserted into a
column of a table. Examples
Indices are created in an existing table to locate rows more quickly and efficiently.
It is possible to create an index on one or more columns of a table, and each index
is given a name. The users cannot see the indexes, they are just used to speed up
queries.
ÿÿ|%&
It creates a simple index on a table. Duplicate values are allowed in simple index.
ÿÿ$%&
0
A view could be used from inside a query, a stored procedure, or from inside
another view. By adding functions, joins, etc., to a view, it allows you to present
exactly the data you want to the user.
7
' . 7
' / is Oracle
Corporation's proprietary procedural extension to the SQL database language, used
in the Oracle database. Some other SQL database management systems offer
similar extensions to the SQL language. PL/SQL's syntax strongly resembles that
of Ada, and just like Ada compilers of the 1980s the PL/SQL runtime system uses
Diana as intermediate representation. The key strength of PL/SQL is its tight
integration with the Oracle database. PL/SQL is one of three languages embedded
in the Oracle Database, the other two being SQL and Java.
6
PL/SQL made its first appearance in Oracle Forms v3. A few years later, it was
included in the Oracle Database server v7 (as database procedures, functions,
packages, triggers and anonymous blocks) followed by Oracle Reports v2.
7
' programs consist of $, , and " ,.
Each of these is made up of the basic PL/SQL unit which is the block. Blocks take
the general form:
-- Declaration block (optional)
-|
-- Program proper
2
|
-- Exception-handling (optional)
/* Sample comment spanning multiple lines... */
"1
1
To define a character variable, the programmer normally appends the variable type
VARCHAR2 to the name definition. There follows in brackets the maximum
number of characters which the variable can store.
varchar, char, long, raw, long raw, nchar, nchar2, clob, blob, bfile
1
Oracle provides a number of data types that can store dates (DATE, DATETIME,
TIMESTAMP etc), however DATE is most commonly used.
TO_DATE('31-12-2004','dd-mm-yyyy')
"or"
To convert the dates to strings one uses the function TO_CHAR (date_string,
format_string).
3. Both sql and pl/sql are languages used to acess data with in oracle data
base....sql writtens querys by using ddl,dml,dcl etc...where plsql uses
cursors,triggers,procedures etc.. In sql querys process at a time where as in plsql it
done step by step or recoed by record ...
½p Oracle server
½p Oracle Forms (Version 3 and later)
½p SQL*Menu (Version 5 and later)
½p Oracle Reports (Version 2 and later)
½p Oracle Graphics (Version 2 and later)
c
p
c
p
You can call a stored procedure from another PL/SQL block, which can be either
an anonymous block or another stored procedure. For example, you can call a
stored procedure from Oracle Forms (Version 3 or later).
Also, you can pass anonymous blocks to Oracle from applications developed with
these tools:
c
p
c
p
$"
1$
1$
c
p
c
p
"
The following code segment shows the IF-THEN-ELSIF construct. The ELSIF and
ELSE parts are optional so it is possible to create simpler IF-THEN or, IF-THEN-
ELSE constructs.
IF x = 1 THEN
sequence_of_statements_1;
ELSIF x = 2 THEN
sequence_of_statements_2;
ELSE
sequence_of_statements_N;
END IF;
CASE
WHEN x = 1 THEN sequence_of_statements_1;
WHEN x = 2 THEN sequence_of_statements_2;
ELSE sequence_of_statements_N;
END CASE;
CASE x
WHEN 1 THEN sequence_of_statements_1;
WHEN 2 THEN sequence_of_statements_2;
ELSE sequence_of_statements_N;
END CASE;
$
As a procedural language by definition, PL/SQL provides several iteration
constructs, including basic LOOP statements, WHILE loops, FOR loops, and
Cursor FOR loops.
"
%&
LOOP
statement1;
statement2;
END LOOP;
Loops can be terminated by using the EXIT keyword, or by raising an exception.
Syntax:
WHILE LOOP
...do something...
END LOOP;
*$
*$
FOR RecordIndex IN (SELECT person_code FROM people_table)
LOOP
DBMS_OUTPUT.PUT_LINE(RecordIndex.person_code);
END LOOP;
3
"
Syntax:
GOTO record
Where record is place in the PL/SQL to which goto label shift the control of
program.
ÿ
'.ÿ
'/
It is a part of PL/SQL. Oracle treats a series of operators as a single entity. The
changes made to the table is a two step process, First the changes requested are
done, secondly to make change permanent a commit statement has to be given at
SQL prompt. A roolback statemet given at the SQL prompt can be used to undo a
part of entire transaction.
1.p |ÿ saves work done.
2.p
0
| ÿ identifies a point in transaction to which you can later roll
back.
3.p )ÿ restore database to original since the last COMMIT.
4.p
| ÿ Change transaction options like isolation level and
what rollback segment to use.
%&Commit;
Rollback [to[savepoint]savepointname];
Savepoint savepoint_name;
After execution
'&(7
', &
#!p |"$á!
á!p $"+á888+#:889,!
R!p % á89888! |
4;á89888 $9 "
$!
%$
The set of rows returned by a query can consist of zero, one, or multiple rows,
depending on how many rows meet your search criteria. When a query returns
multiple rows, one can explicitly declare a cursor to process the rows. Moreover,
one can declare a cursor in the declarative part of any PL/SQL block, subprogram,
or package.
We use three commands to control a cursor: OPEN, FETCH, and CLOSE. First,
we initialize the cursor with the OPEN statement, which identifies the result set.
Then, you can execute FETCH repeatedly until all rows have been retrieved. When
the last row has been processed, we release the cursor with the CLOSE statement.
0
<* <|
< * <(
When we declare a cursor, we name it and associate it with a specific query using
the syntax:
CURSOR cursor_name [(parameter[, parameter]...)]
$
Opening the cursor executes the query and identifies the result set, which consists
of all rows that meet the query search criteria. For cursors declared using the FOR
UPDATE clause, the OPEN statement also locks those rows.
"
We use the OPEN statement to pass parameters to a cursor. Unless we want to
accept default values, each formal parameter in the cursor declaration must have a
corresponding actual parameter in the OPEN statement.
*
The FETCH statement retrieves the rows in the result set one at a time. Each fetch
retrieves the current row and then advances the cursor to the next row in the result
set.
The CLOSE statement disables the cursor, and the result set becomes undefined.
Once a cursor is closed, we can reopen it.
Oracle implicitly opens a cursor to process each SQL statement not associated with
an explicitly declared cursor. PL/SQL lets you refer to the most recent implicit
cursor as the SQL cursor. You cannot use the OPEN, FETCH, and CLOSE
statements to control the SQL cursor. But, you can use cursor attributes to get
information about the most recently executed SQL statement
1:
When appended to the cursor or cursor variable, these attributes return useful
information about the execution of a data manipulation statement. You can use
cursor attributes in procedural statements but not in SQL statements
the implicit cursor attributes are referred by preceding the implicit cursor attribute
with cursor name.(i.e sql).
'<*
| %"$9 <*
&
'<|
Oracle closes the SQL cursor automatically after executing its associated SQL
statement. As a result, %ISOPEN always yields FALSE.
'<(
In the following example, you use %ROWCOUNT to take action if more than ten
rows have been deleted:
"&
"$%&
"&
"$%&
"&
c
p
c
p
"$%&
a.p %Type
b.p %Rowtype
!p <$& This attribute is used when declaring variables that refer to data
base column by using type variable; we need the name of columns and table
to which the variable correspond.
%& variable_name <table_name>.<column_name>%type.
!p < $&This attribute is used to declare the single variable for various
columns in a table.
'#&(7
'"$1
"$"#889"$ "9
"$.
99
9969/!
<$&
%
%
<(5 &
Before execution
After execution
!p *"""1&
Syntax: fetch <cursor_name> into variable_name;
!p
%"$!
!p &
Syntax: close <cursor_name>;
c
p
c
p
'&(7
',$9"9="$
$""#8!
< $&
%
%
<$&
%
%
<$&
%
%
< $&
%
%
%&
Loop
<SQL statement>;
'&$9"9="$$""#8
$$!
%
c
p
c
p
'&$9"9$R$"$
$$!
%
%