You are on page 1of 6

Collections : [8.

0]
Student Information :
roll name course book_id title doi dor
11
101 ram
oracle
12
13
------------------------------------------------------------16
102 hari
oracle
18
21
-------------------------------------------------------------T1
T2
----------roll (pk)
book_id
name
title
course
doi
dor
roll (fk)
Collections (8.0)
--------------------A group of similar rows stored at one location.
2 Types:
1. Nested Tables
Table with in a table
A column holds a table of contents in it.
2. Varrying Arrays ( Varrays )
It is an array of elements stored in a column.
Nested Table Example:
i). create type book_type as object
( book_id number(4), title varchar2(20),
doi date, dor date );
/
* Object representing Table of books
ii). create type books is table of book_type;
iii). create table stu_lib (roll number(3),
name varchar2(20), course varchar2(20),
binfo books) Nested table binfo store as

book_table;

iv) desc book_type


desc books
desc stu_lib
v) insert into stu_lib values(101,'RAM','Oracle9i',
books
( book_type(11, 'sql' , sysdate, sysdate + 10),
book_type(12, 'pl/sql' , sysdate, sysdate + 15),
book_type(13, 'DBA' , sysdate, sysdate + 20)));
vi) select * from stu_lib;
select name,binfo from stu_lib;
--------------------------------------------------------------DML on Nested Table:
THE - operator is used to perform DML
on Nested table.
It holds the nested table content in buffer
memory for manipulation purpose.

Ex:
* Adding a Book ( Only 1 book allowed )
insert into
THE(select binfo from stu_lib where roll = 101)
values(book_type(15,'DBA',sysdate,sysdate + 10));
* Changing a Book details
Update
THE(select binfo from stu_lib where roll = 101)
set dor = dor + 3 where book_id = 12;
Update
THE(select binfo from stu_lib where roll = 101)
set title = 'Tuning' where book_id = 15;
* Removing a book info
delete from
THE(select binfo from stu_lib where roll = 101)
where book_id = 12;
--------------------------------------------------------------Varrying Array Example:
i) create type book_type as object
(book_id number(4), title varchar2(20), doi date,
dor date);
/
* Object representing Array of books
ii) create type barray is varray(3) of book_type;
iii) create table library (roll number(3),name
varchar2(20), binfo barray);

varchar2(20), course

iv) desc book_type


desc barray
desc library
v) insert into library values(101,'RAM','Oracle9i',
barray(book_type(11, 'sql', sysdate,sysdate + 10),
book_type(12, 'pl/sql' , sysdate, sysdate + 15),
book_type(13, 'DBA' , sysdate, sysdate + 20)));
vi) select * from library;
select name,binfo from library;
--------------------------------------------------------------Varray Structure: Library
roll name course book_id title doi dor
11
101 ram
oracle
12
13
--------------------------------------------------------------Nested Table
Vs
Varray
Stored outside the table
Stored with in the table
DML is allowed
DML Not Allowed
Stores unlimited data
Stores limited data
Note:
Collections will not support constraints.
Long, RAW, LOB data types are not valid in
Collections will not support Developer 6i,VB (GUI
JAVA supports collections.

collections.
Tools) .

--------------------------------------------------------------Ex 2: Varray
create type blist is varray(5) of varchar2(25);
create table items(itno number(3),
name varchar2(20), brands blist);
insert into items values(101,'Television',
blist('SONY','LG','ONIDA','SAMSUNG','TCL'));
insert into items values
FB'));

(102,'Micro-oven',blist('LG','ONIDA','I

update items set brands =


MSUNG')
where itno = 102;

blist('LG','ONIDA','IFB','KENSTAR','SA

desc blist
desc items
select * from items;
select name,brands from items;
--------------------------------------------------------------Data Partitioning with Partition Tables:
Used to manage huge loads of data in table by
ns.
Improves the performance of Oracle while
ng data from Huge Tables.
Ex:
create table emp_part (ecode number(2) primary
number(10,2))
partition by range (ecode)
( partition p1 values less than (11),
partition p2 values less than (21),
partition p3 values less than (31),
partition p4 values less than (41),
partition p5 values less than (maxvalue));
Partition Limits :
p1 -- 1 - 10
p2 -- 11 - 20
p3 -- 21 - 30
p4 -- 31 - 40
p5 -- 41 - N
insert into emp_part values (1,'RAM',12000);
insert into emp_part values (3,'RAM',13000);
insert into emp_part values (7,'RAM',17000);
insert into emp_part values (11,'RAM',2000);
insert into emp_part values (13,'RAM',3000);
insert into emp_part values (17,'RAM',7000);
insert into emp_part values (21,'RAM',22000);
insert into emp_part values (23,'RAM',23000);
insert into emp_part values (27,'RAM',27000);
insert into emp_part values (31,'RAM',10000);
insert into emp_part values (33,'RAM',14000);
insert into emp_part values (37,'RAM',15000);

creating Logical Partitio


retrieving or manipulati
key, ename varchar2(20), sal

insert
insert
insert
insert

into
into
into
into

emp_part
emp_part
emp_part
emp_part

values
values
values
values

(41,'RAM',31000);
(43,'RAM',33000);
(47,'RAM',37000);
(67,'RAM',57000);

select * from emp_part;


select * from emp_part partition (p2);
select * from emp_part partition (p3)
where sal > 20000;
update emp_part partition (p2)
set sal = sal + 3000 ;
alter table emp_part drop partition p5;
alter table emp_part add partition
p5 values less than (51);
alter table emp_part add partition p6 values less
than (maxvalue);
p5 -- 41 - 50
p6 -- 51 - n
--------------------------------------------------------------Ref Cursors:
- Dynamic cursors
- supports to define the cursor without select
- select statement will be provided while "opening"
- used to send cursor as an parameter in sub
- made easy to transfer huge data thru sub
p1(a number,b char) --- p1(1001,'RAM');

statement.
cursor.
programs.
programs.

Syntax: Type <Ref cursor name> is Ref cursor;


create package pack1 as
type rcur is ref cursor;
end pack1;
** Procedure returning multiple rows thru OUT
create or replace procedure get_rows
(vdept in number, vcur out pack1.rcur) is
begin
open vcur for select empno,ename,sal,job from
end;
Using Procedure:
declare
pcur pack1.rcur;
veno number(4); vname varchar2(20);
vsal number(12,2); vjob varchar2(20);
begin
-- calling procedure
get_rows(30,pcur);
-- printing cursor contents
dbms_output.put_line(' Employee Details are ');
loop
fetch pcur into veno,vname,vsal,vjob;
exit when pcur%notfound;
dbms_output.put_line(veno||' '||vname||' '||vsal

parameter :

emp where deptno = vdept;

||' '||vjob);
end loop;
close pcur;
end;
Re-using Ref cursor:
declare
scur pack1.rcur;
vroll number(3); vname varchar2(20);
vfee number(5);
begin
open scur for select roll,sname,fee_paid from
stu_info where course =
'&course';
loop
fetch scur into vroll,vname,vfee;
exit when scur%notfound;
dopl(vroll||' '||vname||' '||vfee);
end loop;
close scur;
end;
--------------------------------------------------------------Important Topics:
Joins, 9i Joins, Constraints, Sub queries, Views, Index, clusters, Pseudo colu
mns, All 8.0 features, Date Manipulations, Procedures, Functions, Triggers, P
ackages, Utilities, Pragma, Autonomous Transactions, Exception_init, Ref curs
ors, Temporary tables, Normalization, Architecture,
Partition Tables, File I
/O.
--------------------------------------------------------------Roles of an Programmer in Oracle : ( Resume )
* Designing the database objects using
Normalization .
* Applying Constraints, Indexes to maintain Data
Integrity while definin
g objects.
* Defining code components like Triggers to apply
User defined restriction
s in database as per client
requirement .
* Defining Procedures , Functions & Packages as
per client requirement
.
* Generating different types of Queries for
reporting purpose.
--------------------------------------------------------------Versions Features:
Oracle 6.0 - It is an DBMS Tool
Oracle 7.x - It is an RDBMS Tool (7.0 / 7.1 / 7.2 /
7.3)
Oracle 8.0 - It supports OOPS Features.(ORDBMS)
New Features: Objects , Object with Methods, Nested Tables, Varrying Arrays,
Rename, Sharing Columns, Partition Tables, Key Preserved Table, Inline Views,
Scalar Query, File I/O ,Autonoumus Transactions , Trim, Reverse, stddev, vari
ance , ceil, floor ,LOBS, Returning into, Bulk Collect,
bulk bind, Rollup, Cube.
Oracle 8i : It is in_built with JAVA
New Features: SQLJ, Iterators, Temporary Tables,
ggers, case,
Materialized views.

Drop Column, Instead of Tri

Oracle 9i : Supports Advanced Features of JAVA.


New Features : Supports XML .
New Date Functions, New General Functions ,
Multiple Inserts, Merge, Rena
me columns &
Rename Constraints , 9i Joins,Analytical Functions
Oracle 10g :
Supports Grid Technology - used to store EJB

components directly into

Database .
Using Aggregates in Returning into clause, spool Append, Using Regular Exp
ressions while searching character data . Provides High performance .
Supported with More Advanced Features for DBA.
--------------------------------------------------------------Oracle 8i:
Java is a Built_in software
Supports to execute Java programs with in oracle
server or client System.
SQLJ : It is an Transalator.
It will check for SQL stmt syntax errors and
translate the Sql comman
ds into Java equivalent
code. After Translation it returns .Java file .
Sql stmts are provided in below format in Sqlj
)
#sql { DDL, DML , TCL , DCL };
Steps:
Provide Path settings and User details in
em file.
1. Open Notepad and add the Code
2. save file as "filename.sqlj"
3. C:\>sqlj filename.sqlj -- check for sql syntax
and translate into .java file
4. C:\>javac filename.java -- compiles java
.class file
5. C:\>java filename -- Execute .class file and
.

script. ( filename.sqlj

"connect.properties" syst

program and gives


gives final output

Iterators:
Used to retrieve data from Oracle table to Java
program. similar to cur
sors in PL/SQL.
2 Types
1. Named Iterator - Similar to cursor with For loop
2. Positional Iterator - Similar to cursor with
Operations
---------------------------------------------------------------

You might also like