Академический Документы
Профессиональный Документы
Культура Документы
consists
of
two
or
more
computers
CLIENT
CLIENT
S
LAN /
CLIENT
WAN
S
RDBMS
SERVER
DATA
STORAGE
PRINTERS
CLIENT
The Client is the front END application of a database which
interacts
with the server. The Client has more responsibility for accessing
the data, it concentrates on the requests. The processing and
presentation is managed by the server.
Dept. of Computer
Science
SERVER
The Server executes the Oracle software and these with the
function required for simultaneous and shared data excess. The
server receives and processes the SQl and PL/SQL declaration and
that originates in the client application.
ORACLE
Oracle is one of the powerful RDBMS products that provide
efficient solutions for database applications. Oracle is the product
of Oracle Corporation which was founded by LAWRENCE ELLISION
in 1977. The first commercial product of oracle was delivered in
1970. The first version of oracle 2.0 was written in assembly
language. Nowadays commonly used versions of oracle are
ORACLE 8, 8i & 9i Oracle 8 and onwards provide tremendous
increase in performance, features and functionality.
FEATURES OF ORACLE
Client/Server Architecture
Large database and Space Management
Concurrent Processing
High transaction processing performance
High Availability
Many concurrent database users
Controlled availability
Openness industry standards
Manageable security
Database enforced integrity
Distributed systems
Portability
Compatibility
ORACLE SERVER TOOL
Dept. of Computer
Science
Dept. of Computer
Science
Select
Update
Delete
Insert
Dept. of Computer
Science
will
not
be
padded
with
spaces.
Syntax
is
VARCHAR(SIZE)
Example is VARCHAR (20) OR VARCHAR2 (20)
LONG:
Dept. of Computer
Science
DATE: This data type is used to represent data and time. The
standard format id DD-MM-YY as in 13-JUL-85. To enter dates
other than the standard format, use the appropriate functions.
Date Time stores date in the 24-hour format. By default, the
time in a date field is 12:00:00 am, if no time portion is
specified. The default date for a date field is the first day of the
current month. Syntax is DATE
LONG RAW: LONG RAW data types are used to store binary
data, such as Digitized picture or image. Data loaded into
columns of these data types are stored without any further
conversion. LONG RAW data type can contain up to 2GB.
Values stored in columns having LONG RAW data type cannot
be indexed. Syntax is LONGRAW (SIZE)
RAW: It is used to hold strings of byte oriented data. Data type
can have a maximum length of 255 bytes. Syntax is RAW(SIZE)
TRANSACTION STATEMENTS
COMMIT: A COMMIT ends the current transaction and makes
permanent any changes made during the transaction. All
transactional locks acquired on tables are released. Syntax is
COMMIT [work] [comment text];
Where
Work is optional and comment text is used to specify
comment
ROLLBACK: A ROLLBACK does exactly the opposite of COMMIT.
It ends the transaction but undoes any changes made during
the transaction. All transactional locks acquired on tables are
released. Syntax is
ROLLBACK [WORK] [TO [SAVEPOINT] save point]
Where
WORK is optional and is provided for ANSI compatibility.
SAVEPOINT is optional and is used to rollback a partial
Dept. of Computer
Science
Dept. of Computer
Science
SQL COMMANDS
CREATE TABLE:
TABLE
student
(rollno
number
(4),
name
varchar2 (15));
SELECT: The select command of sql lets you make queries
on the database. A query is a command that is given certain
specified information from the database tables. It can be
used to retrieve a subset of rows or columns from one or
more tables.
Syntax to create a table is
SELECT
<column_name1>,<column_name2>
FROM
<tablename>;
Example is
SELECT empno, ename, sal from emp;
CREATE TABLE FROM ANOTHER TABLE : We can create a
table by applying as subquery clause from another clause. It
Dept. of Computer
Science
will create the table as well as insert the rows returned from
subquery. Syntax to create table from another table is
CREATE TABLE tablename(<column1>,<column2>,)
AS
SELECT
<column1>,<column2>
FROM
<tablename>;
Example is
CREATE TABLE stud(empno,ename,salary)
AS SELECT empno,ename,sal FROM emp;
ALTER TABLE : After creating a table one may have need to
change the table either by add new columns or by modify
existing columns. One can do so by using alter table
command.
Syntax to add a column is
ALTER
TABLE
tablename
ADD(col1
datatype,col2
datatype);
Syntax to modify a column is
ALTER TABLE tablename MODIFY(col1 datatype,col2
datatype);
DROP TABLE: To remove the definition of oracle table, the
drop table statement is used. Syntax to drop table is
DROP TABLE tablename
RENAME : One can change the name of a table by rename
command Syntax to rename table is
RENAME oldname TO newname
DELETE: One can delete data fron table by using delete from
statement. The delete statement removes rows from table
but it doesnt release storage space. Syntax of delete rows
from table is
DELETE FROM tablename WHERE <condition>;
Dept. of Computer
Science
<col1>,<col2>
FROM
tablename
WHERE
<cond>;
Example is
SELECT ename,sal FROM emp WHERE sal > 2000;
ORDER BY CLAUSE: You can sort the results of query ina
specific order using order by clause. It allows sorting of query
Dept. of Computer
Science
Dept. of Computer
Science
ALL
<column1>,<column2>
FROM
<tablename>;
Example is
SELECT ALL city FROM suppliers;
SET OPERATORS
Set keywords are used to combine information of
similar type
from one or more than one table. Set operations and the operators
are based on set theory. It consumes two or more queries into one
result. The types of set operators are: UNION : The union clause merges the outputs of multiple
queries into a single set of rows and columns. It combines rows
returned by two select statements by eliminating duplicate
rows. Syntax is
SELECT <statement> UNION SELECT <statements>;
Example is
SELECT designation FROM emp_info WHERE deptt=comp
UNION
SELECT designation FROM emp_info WHERE deptt=eco;
Dept. of Computer
Science
Dept. of Computer
Science
Dept. of Computer
Science
Dept. of Computer
Science
The types of indexes are: UNIQUE : It doesnt allow duplicate values for indexed
columns.
Example is
CREATE UNIQUE INDEX mohit ON EMP (ename);
DUPLICATE : It allows duplicate values for indexed columns.
Example is
CREATE DUPLICATE INDEX mohit ON EMP (ename);
COMPOSITE : multi column indexes.
Example is
CREATE UNIQUE INDEX mohit ON EMP (ename, sal);
FUNCTIONAL : perform some functions on fields and then
indexes it. Example is
CREATE INDEX mohit ON EMP (sal+100);
GRANTING AND REVOKING PERMISSIONS
GRANT : The Grant statement provides various types of access
to database
objects such as tables, views and sequences. A privilege is
consent to execute an action or to access another user
object. These consents can be given by grant statement.
Syntax is
GRANT {object privileges}
TO username
ON object name
Dept. of Computer
Science
Perform some operation on the object. The user can grant all the
privileges or grant only specific object privileges.
ALTER
the.
ALTER TABLE command.
DELETE
INDEX
DELETE command.
the
CREATE INDEX command.
INSERT
INSERT
Command.
SELECT
UPDATE
with the
UPDATE command.
Example to grant select & insert privileges on table item to user
named as mohit.
GRANT SELECT, INSERT ON item TO mohit;
Example to grant all privileges on table EMP to user named as
chiku.
GRANT ALL ON EMP TO mohit;
REVOKE :
Dept. of Computer
Science
Dept. of Computer
Science
FROM
table1,table2
WHERE
table1.field=table2.field;
Example is
SELECTename,
dname
FROM
emp,
dept
WHERE
emp.deptno=dept.deptno;
Cartesion join : When the join condition is omitted the
result is Cartesian join of two or more tables in which all the
combinations of rows will be displayed. All the rows are joined
to all rows of the second table. Syntax is
Dept. of Computer
Science
Dept. of Computer
Science
query. Example is
SELECT deptno FROM emp WHERE ename =MILLER;
Multiple row : Subqueries that return more than one row
called multiple row queries. Operators like IN,ALL,ANY are
used. Example is
SELECT ename,sal,deptno FROM emp WHERE sal IN
(SELECT min(sal) FROM emp GROUP BY deptno);
Multiple
column
It
returns
more
than
one
column .Example is
SELECT ordid , prodid , qty FROM item WHERE (qty,prodid) IN
(SELECT prodid,qty FROM item WHERE ordid = 605 AND ordid
<> 605);
CONSTRAINTS
table
statement to constraint more than one column.
Dept. of Computer
Science
-- at column
level
UNIQUE COLUMN_NAME DATA_TYPE(SIZE)
-- at table
level
Example is
CREATE TABLE dept(deptt varchar2(25) UNIQUE);
CREATE TABLE dept(deptt varchar2(25),UNIQUE(dept));
PRIMARY KEY : Primary key refers to one or more column
values in a table that can uniquely identify each row in a table.
A primary key column cannot contain nulls and is unique by
default. Syntax is
COLUMN DATA_TYPE(SIZE) PRIMARY KEY -- at column level
PRIMARY KEY COLUMN DATA_TYPE(SIZE) -- at table level
Example is
CREATE TABLE dept(deptt varchar2(25) PRIMARY KEY);
CREATE TABLE dept(deptt varchar2(25),PRIMARY KEY(dept));
Dept. of Computer
Science
TABLE
dept(deptt
varchar2(25)
REFERENCES
emp_info);
CREATE TABLE dept(deptt varchar2(25),PRIMARY KEY(dept)
FOREIGN KEY(dept) REFERENCES emp_info);
FUNCTIONS
Functions make the result of the query easier and are
used to manipulate the data values. Following are the functions
are
String or character functions
Number functions
Aggregate functions or group functions
Date functions
Conversion functions
Character Manipulation functions
Dept. of Computer
Science
select
ascii(b)from dual;
lpad : It pads the leading spaces to the left side of the column
char1 with the char2, so that the total width becomes equal to
the value n. If char2 is absent, it pads the char1 on the left
side with blank spaces to the total width of n.
Example is select lpad(dname,12,*) from dept;
Ltrim : It removes all the blank spaces from the left side of the
stringif no char is specified. If we give a char, then it removes
the leading occurrences of that charcter from the string.
Example is select ltrim(dname.S) from dept;
Dept. of Computer
Science
Rpad : This function pads the leading spaces to the right side
of the column char1 with the char2, so that the total width
becomes equl to the value n.
Example is select rpad(dname,12,*)from dept;
Rtrim : This function removes all the blank spaces from the
right
side
if
no
char
is
specified.
Example
is
select
Dept. of Computer
Science
Group functions
Count : This function returns the number of rows or non-null
values for column x. Syntax is count([distinct|all]column name)
Example is select count(empno)from emp;
Sum : This function ireturns the sum of values for the column x.
This function is applied on columns having numeric datatype
and it returns the numeric value.
Syntax is sum([distinct|all]column name)
Example is select sum(sal) from emp;
Avg : Ths function returns the average of values for the column
x. It ignores the null values in the column x. Syntax is
avg([distinct|all]column name)
Example is select avg(sal),count(sal) from emp;
Min : This function returns the minimum of values for the
column x for all the rows. Syntax is min([distinct|all]column
name)
Example is select min(sal) from emp;
Max : This function returns the maximum of values for the
column x for all the rows. Syntax
is max([distinct|all]column
name)
Example is select min(sal),max(sal) from emp;
Number functions
Abs : It obtains the absolute value for the number x.
Example is
Dept. of Computer
Science
Dept. of Computer
Science
Dept. of Computer
Science
string
after
the
beginning
date.
Syntax
is
Dept. of Computer
Science