intro Lecture-1

150 downloads 164 Views 977KB Size Report
Oracle 9i Development by Example. By Dan Hatka. Reference Books. ▫. Introduction to Oracle: SQL and PLSQL. ▫. Build Internet Applications I by Oracle Press.
RDBMS using Oracle 2+1 Relational Database Management System Using Oracle

E-mail: [email protected]

RDBMS Using Oracle This course will cover…. n n n

Oracle RDBMS Environment Advance Structured Query language (SQL) Procedural Language / Structured Query language (PL/SQL)

n

Oracle Developer Forms (GUI) Oracle Developer Reports (GUI)

n

Oracle database Administration

n

1

SQL

PL/SQL

Oracle Form Builder

Oracle Graph & Procedure Builder

Oracle Report Builder

SQL/PLSQL n n

n

n n n n n n n

Data Types & Oracle RDBMS limits Getting information, Adding, Updating & Deleting information SQL Arithmetic, Group, Character and Date functions Creating and using views Creating Index Functions Procedures Implicit and Explicit Cursors Triggers etc.

2

Front-end Development n

Oracle Forms/Reports Development • • • •

Creating frontfront -end forms and menus Working with form objects Creating buttons, text items, images, blocks etc Creating reports and graphs

After completion of this course you will be able to develop complete database applications using Oracle database and Oracle development Suit by writing SQL and PL/SQL reusable code

3

Books OCA/OCP Introduction to Oracle 9i SQL

n

Study Guide Exam IZ0IZ0-007 by Chip Dawes, Biju Thomas

Oracle 9i PL/SQL A Developer’s Guide By Bulusu Lakshman

n

Oracle 9i Development by Example By Dan Hatka

n

Reference Books n n n n n

Introduction to Oracle: SQL and PLSQL Build Internet Applications I by Oracle Press Build Internet Applications II by Oracle Press Oracle Reports by Oracle Press Oracle 8i/9i by Oracle press

(OCP track student guide)

4

Lets begin………

Installation

5

Oracle 8/8i

Windows NT/2000/xp n n

Oracle 8 for NT or Oracle8i ver ver.. (8.1.5) Developer 6i

Free space required (approx. 1.2 GB) Install Oracle and developer by giving different home names and at different locations. n

e.g for ORACLE Home Name à ora_home For Developer 6i Home Name à dev_home

6

Oracle 9i n n

Oracle 9i Database Oracle 9i Development Suite

Free space required (approx. 3 GB) Min RAM required is 512Mb Recommended for Personal Computers Oracle 8/8i ver 8.1.5 or higher and Developer 6i or Oracle 8/8i Database and Oracle 9i Development suit

Oracle Database Architecture Oracle Server Instance

User

User Process SQL*Plus, VB, …

Server Process

Background Processes

Shared Global Area

SQL, PL/SQL

Database Tables, Indexes, Constraints, Triggers, …

Data Files

System Files

7

SQL In Oracle RDBMS

PL/SQL

Oracle Form Builder

Oracle Graph & Procedure Builder

Oracle Report Builder

Relational Database Management System Using Oracle

Lecture 1 1. 2. 3. 4. 5. 6. 7.

Overview of the Oracle RDBMS Overview of SQL* Plus Data Types in Oracle SQL Plus Oracle RDBMS limits Getting information from a table Selecting limited rows/columns Comparison Operators

8

SQL queries n

What is query?

Answer can be…. “Query is a request towards the database in order to retrieve information from tables”

SQL Query User

Query Analyzer

Output

Database

9

Database

Oracle RDBMS Limits Tables

No Limit

n

Rows Columns in a table Characters in a character field Number Field Tables joined in a query Level of nested sub queries

No Limit 254 240 105 No limit 255

n

Characters in a name

30

n n n n n n

10

SQL n

n

SQL (Structural Query Language) is a language which is used to manipulate data in any RDBMS. SQL is not case sensitive.

SQL Plus SQL Plus is a program for working with an ORACLE database by using SQL language. v Create tables in a database v Store , change & retrieve information in/form the table v Perform calculations

11

SQL commands categories

n

SQL commands are divided into three main categories • Data Definition Language (DDL) • Data Manipulation Language (DML) • Transaction Control Commands (TCC)

Data definition language (DDL commands) Commands that are performed on a table or user v Create, Alter, Drop v Grant, Revoke

(Related to tables) (For Permissions e.g. read, write etc..)

Data Manipulation Language (DML commands) Commands that are performed on table data v

v v v

SELECT DELETE INSERT UPDATE

(Select data in rows and columns from one or more tables.) (Remove rows from a table.) (Add new rows to a table.) (Change data in a table.)

Transaction Control Commands v Commit & Rollback

à to save or undo changes

12

ORACLE Sample tables n n n n

EMP Bonus Dept Salgrade Connect Oracle SQL user name: Password: Database string:

orcl

scott tiger orcl

Scott is the default user of ORACLE In you home computer use null or your computer name as Host String.

13

The system table “tab”

n

n

tab: It’s the table of tables, i.e. stores the names of all the tables created by the user select * from tab; • lists all the tables created

SELECT statement

Display all data from a table SQL> Select * from ; SQL> Select * from emp emp;;

SQL> Select * from emp ; • Displays data stored in emp table

14

SELECT statement Display specified data from a table SQL> Select select ename from emp emp;; SQL> select * from dept; SQL> select deptno from dept;

15

Table description command SQL> desc desc emp ; (where emp is the table name) SQL> desc dept; ………..

The WHERE Clause WHERE clause is used when we want to select few records from a table (based on condition/criteria). Suppose we have a CAR table CarNo 2344 3445 3467 9878

Color RED BLACK RED BLUE

Table CAR -------------CarNo Number(4) Color char(15)

16

CAR table CarNo 2344 3445 3467 9878

Color RED BLACK RED BLUE

Suppose we want to select RED cars only. For this we will write this query SQL> select * from cars where Color = ‘RED’; 1- What will be the query if we want to select car whose number is 2344? 2- Select carcar-numbers from car table whose color is RED?

Comparison Operators n n n n n n n n n

= ! = or > >= < select * from emp where sal = 800; Display records with salary is equal to 800

! = or Not equal to n n

SQL> select * from emp where sal 800; SQL> select * from emp where sal != 800;

Display records with salary is not equal to 800

18

>

n

Grater then

SQL> select * from emp where sal > 800; Display records with salary is grater then 800


select * from emp where sal < 800;

Display records with salary is less then 800

19

>=

n

Grater then equal to

SQL> select * from emp where sal >= 800; Display records with salary >= 800

BETWEEN …AND n

SQL> select * from emp where sal between 200 and 800; Display records where salary is from 200 to 800

NOTE: Records with salary 200 and 800 are also included.

20

IN (list)

n

any of a list of values

select * from emp where sal in (200,800,600); Display records where salary is either 200 or 800 or 600

LIKE n

match a character pattern

select * from emp where ename like ‘_dam’; Display records where ename column has “dam” at the end and there is one character at the beginning of ename.

n

select * from emp where ename like ‘A%’; Display records where ename begins with ‘A’.

21

and ……. or n

SQL> select * from emp where sal = 800 or sal = 600 Display records where salary is either 600 to 800

n

SQL> select * from emp where sal is 800 and ename like ‘A%’; Display records where salary is equal to 800 and ename begins with ‘A’

Lab Practice

22

Practice Following SQL Queries PERFORM THE FOLLOWING QUERIES: Part 1 n n n n n n n

List all rows of the table emp emp.. Display the structure of the table emp emp.. Display the structure of the table dept. List all employees name from table emp emp.. List all jobs from emp table. List all salaries from emp table. List all commission, mgr from emp table.

Part 2 n

n

n

n

n

Display records where salary is either 600 or 800. Display records where ename column has “dam” at the end and there is one character missing at the beginning of ename ename.. Display records where salary is either 200 or 800 or 600 Write a SQL statement which selects list of employees whose salary is between 200 to 800 or their name ends with ‘m’. Write a SQL statement which selects names of the employees whose salary is either 200 or 800 or the character ‘d’ comes in their name.

23

Part 3 n

List all departments number from table emp emp..

n

List all employees number, employees name, jobs, mgr from table emp emp..

n

List all employees number, employees name, jobs, mgr, salaries from table emp emp..

n

n

List all employees number, employee name, jobs, mgr, salaries, hiredate from emp table. Write a SQL statement which selects list of employees whose salary is either 200 or 800 (By using in operator) and/or their name starts with ‘A’.

Be Happy J

24