2. OverviewOverview
Personal DBMS Vs Client/Server DBMSPersonal DBMS Vs Client/Server DBMS
Oracle 8 EnvironmentOracle 8 Environment
SQL – syntax and examplesSQL – syntax and examples
PL/SQL-introductionPL/SQL-introduction
3. Server
Gets file requests from clients
Sends files to client
Receives files back from clients
NETWORK
Client A
Sends file requests to server
Receives files from server
Updates data
Sends files back to server
Client B
Sends file requests to server
Receives files from server
Updates data
Sends files back to server
Personal
DBMS
4. Personal DBMS - ProblemsPersonal DBMS - Problems
Demand on the client and the networkDemand on the client and the network
Does not perform table locking automaticallyDoes not perform table locking automatically
Not fault tolerant in the case of client failureNot fault tolerant in the case of client failure
Do not have file based transaction loggingDo not have file based transaction logging
5. Server
Gets data requests from clients
Adds, Deletes and updates data
Sends results to clients
NETWORK
Client A
Sends data requests to server
Receives results from server
Sends new data or changes to server
Client B
Sends data requests to server
Receives results from server
Sends new data or changes to server
Client/server
DBMS
6. Client/Server DBMSClient/Server DBMS
Minimal load on the client and the networkMinimal load on the client and the network
Performs table locking automaticallyPerforms table locking automatically
Fault tolerant in the case of client failureFault tolerant in the case of client failure
File based transaction loggingFile based transaction logging
7. Oracle 8 EnvironmentOracle 8 Environment
SQL * PlusSQL * Plus
PL/SQLPL/SQL
Query BuilderQuery Builder
DeveloperDeveloper
Enterprise ManagerEnterprise Manager
Web application serverWeb application server
8. SqlplusSqlplus username/passwordusername/password
ALTER USERALTER USER user-nameuser-name IDENTIFIED BYIDENTIFIED BY newpasswordnewpassword
STASTART filename |RT filename | @@ filenamefilename
CLCLEAREAR SCRSCREENEEN
HELPHELP <command><command>
SAVESAVE filename[.ext] REPLACE|APPENDfilename[.ext] REPLACE|APPEND
EXITEXIT
SQL*Plus commandsSQL*Plus commands
9. SQLSQL
Both an ANSI and ISO standardBoth an ANSI and ISO standard
Types of commands:Types of commands:
1.1. Data Definition Language (DDL) : Create, Alter,Data Definition Language (DDL) : Create, Alter,
Drop, Rename, TruncateDrop, Rename, Truncate
2.2. Data Manipulation Language (DML): Insert,Data Manipulation Language (DML): Insert,
Delete, UpdateDelete, Update
3.3. Data Retrieval: SelectData Retrieval: Select
4.4. Transaction Control: Commit, Rollback, SavepointTransaction Control: Commit, Rollback, Savepoint
5.5. Data Control Language (DCL): Grant, RevokeData Control Language (DCL): Grant, Revoke
15. INSERT INTO Dept( deptid,deptname,location)
VALUES(50,'IT','Dallas');
INSERT INTO Emp(empid,
lname,fname,positionid,
supervisorid,hiredate,
salary,deptid,qualid)
VALUES(227,'howser','Barbara',4,111,'25-AUG-83',45000,10,3);
UPDATE dept SET deptname='Sales' WHERE deptID=50;
DELETE FROM dept
WHERE deptid='50';
16. Data Retrieval:Data Retrieval:
SELECTSELECT [DISTINCT | ALL] {table|view}[DISTINCT | ALL] {table|view}
FROMFROM {table | view}{table | view}
[[WHEREWHERE condition ]condition ]
[[GROUP BYGROUP BY expr [, expr]]expr [, expr]]
[[ORDER BYORDER BY {expr} [ASC | DESC]]{expr} [ASC | DESC]]
select * from dept;select * from dept;
select deptname from dept where deptid='10';select deptname from dept where deptid='10';
select lname,fname from emp order by lname desc;select lname,fname from emp order by lname desc;
select max(salary) from emp group by positionid;select max(salary) from emp group by positionid;
select deptname from dept,emp whereselect deptname from dept,emp where
dept.deptid=emp.deptid and emp.empid='111';dept.deptid=emp.deptid and emp.empid='111';
18. Data Control Language:Data Control Language:
GRANTGRANT [privileges][privileges]
ONON objectobject TOTO user|publicuser|public
[[WITH GRANT OPTIONWITH GRANT OPTION]]
REVOKEREVOKE [privileges][privileges]
ONON objectobject TOTO user|publicuser|public
[[CASCADE CONSTRAINTSCASCADE CONSTRAINTS]]
grant select,update on emp to XYZ ;grant select,update on emp to XYZ ;
revoke update on emp to XYZ;revoke update on emp to XYZ;
19. A PL/SQL Example:A PL/SQL Example:
CREATE OR REPLACE PROCEDURECREATE OR REPLACE PROCEDURE raise_salary (empno INTEGER,raise_salary (empno INTEGER,
increase REAL)increase REAL) ISIS
current_salary REAL;current_salary REAL;
salary_missing EXCEPTION;salary_missing EXCEPTION;
BEGINBEGIN
SELECT salary INTO current_salary FROM emp WHERE emp.empid =SELECT salary INTO current_salary FROM emp WHERE emp.empid =
empno;empno;
IF current_salary IS NULL THENIF current_salary IS NULL THEN
RAISE salary_missing;RAISE salary_missing;
ELSEELSE
UPDATE emp SET salary = salary + increase WHEREUPDATE emp SET salary = salary + increase WHERE emp.empidemp.empid
= empno;= empno;
END IF;END IF;
EXCEPTIONEXCEPTION
WHEN salary_missing THENWHEN salary_missing THEN
UPDATE emp SET salary=0 where emp.empid=empno;UPDATE emp SET salary=0 where emp.empid=empno;
ENDEND raise_salary;raise_salary;