Вы находитесь на странице: 1из 87

ORACLE

What is Database :- Collection interrelated data organized in the form of Rows & Columns.
Why Database System :-
1 !o award the re"etation of data that is to de#elo"ment "rogram for each $""lication %ne Database
&ile in re'uired. Some of the data may be common btween the file( but one $""lication may re'uired the
file ordered in a "articular field and other $""lication is a need of the same file ordered on different field(
i.e.( though the same data in re'uired by the !wo $""lications the data has to be stored in the different
"laces.
) Data retendency reads to in consists of data.
What is D*+S :- ,Database +anagement System :- Collection of related if organized in a structured way
in the form of rows & columns.
+anagement -- +anaging the data which includes(
1 addition( deletion( inserting( modification( u"dation( sorting & generating of Re"orts.
) .ro#ides security for accessing the data.
DBMS Useses
1 $""lication .rogrammers ) ed users ,end / D*$ ,Database $dministrator
1 $""lication .rogrammers -- Writes the $""lication "rograms that use the data base which o"erates on
the data of the database which includes addition( deletion( modification etc.
) 0nd 1sers -- 2ntraction to the system either by in#o3ing a $""lication a .rogram are writting 4uery i
the database 4uerys 5anguage.
/ D*$ -- !he D*$ has to co-adinate the functions of collecting information about the data to stored(
desigining and maintaining the database and security.
$d#antages %f D*+S
1 Retundancy can be Cntrolled -- Centralised control of data by D*$ a#oids the unnessasary du"lication
of data and effectly reduces the total amount of data storage re'uired.
) 2nconstantency can be $warded -- $s retundancy in reduced inconstistency of data can also be
a#oided to same enterd the D*+S ensure that the database in inconsistent by ensuring automatically
a""lications to any other entries.
/ Sharing of Data -- Data*ase allows the sharing of data by any no. of $""lication "rograms or 1sers.
6 Security -- D*+S 7uarantly that only the authorised "ersons can access the data from the database
that in different chec3s can be a""lied to different o"eration.
8 2ntegrity can be +aintained -- Data integrity means data contained in the database both accurate and
contained.
Data +odels
1 &ile *ased +odel ) !raditional Data +odel / Semantic Data +odels
!radional +odels
1 9irarchel +odel ) :etWor3 +odel / Relational +odel
1 9irarchel +odel -- is from file based system.
) :etWor3 +odel -- is the set of hirarchel model.
/ Relational +odel -- de#elo"ed from the conce"t of relations.
SQL
S45 -- Structure 4uery 5anguage to access the relation data based usually "ronounced as Se'uel.
S45 is 2;th 7eneration 5anguage De#elo"ed by 2*+( in 1<=>( but later it was incor"orated by %racle
Cor"oration ,1<=<.
&eatures of S45 :-
1 S45 is a non-"rocedural language i.e.( s"ecify what you re'uire but not how to get it.
) S45 "rocess set of records rather than single record at a time.
/ .ro#ides Commands &or
a 4uering the data b 2nserting( deleting & modification of rows in a table. c $ltering( creating &
deletion of data base %b?ects d Controlling $ccess to the Database %b?ects
-- !hese S45 Commands are a#ailable
1 Data +ani"ulation 5anguage Command ,D+5
) Data Defination 5anguage Command ,DD5
/ Data Control 5anguage Command ,DC5
6 !ransaction .rocessing Command ,!.C
D+5 -- 2nsert( Delete( 1"date
DD5 -- Create( $lter( Dro"
DC5 -- 7rant( Re#o3e
!.C -- Commit( Roll*ac3( Sa#e.oint
Writing of S45 Commands
1 Can be Written on %ne @ +ore 5ines.
) Clauses are 7enerally Written on Se"erate 5ines.
/ Command words canAt be s"lit across lines.
6 S45 commands ae not case senciti#e.
8 S45 commands are entered at S45 "rom"t on the Sub Se'uence 5ines are :umbered 3nown as S45
*uffers.
B $t any +o#ement of !ime only %ne Command can be $cti#e.
= Commands in a S45 *uffer can be 0Cecuted by .ressing A @ A ,slash.
D Command should be entered with a Semicolon , E .
Select Statement --
is used to 4uery the Data from Data*ase.
Date &unctions
Related with Date ty"e of Data.
Sysdate -- 2t Returns Current Date & !ime.
select sysdate from dualE
Date &unctions 1sing $rthematic %"erations
Date F :umber -- $dds :o. of days to the date "roducing date.
Date - :umber -- Substracs :o. of days from the date "roducing date.
Date - Date -- Substracs %ne Date from another "roducing :o. of Days.
select sysdate(sysdateF=(sysdate - =( sysdate - hiredate from em"E
+onths - *etween --
Syn:- months-between,date1( date)
Returns :o. of +onths between Date1 and Date) result can be negati#e or "ositi#e.
select sysdate(months-between,hiredate( sysdate(months-between,A >1-Gan->6A(A /1-$ug->/A
from em"E
$dd-+onths --
add-months,date(n
$dds n no. of months to date where n can be "ossiti#e %R negati#e.
select sysdate(add-months,sysdate()( add-months,sysdate( - / from em"E
:eCt-Day --
neCt-day,date(char
Returns the date of neCt s"ecified day of the wee3 .
select sysdate( neCt-day,sysdate(A+ondayA from dualE
5ast-Day --
last-day,date
Returns 5ast Day of the +onth( that contents date.
select sysdate( last-day,sysdate(last-day,A 1>-+ar->6A from dualE
Round --
round,date(year
Returns first Day of the Hear containing Date( if Date is in the half of the Hear( otherwise returns the first
Day of the following year.
select sysdate(round,sysdate(AyearA from dualE
!runc --
trunc,date(AcharA
&ind the date of the first day of the +onth containing Date( when char I 1
-- if the character is e'ual to year it finds the &irst Day of the Hear containing Date.
select sysdate(trunc,sysdate(AmonthA (trunc,sysdate(AyearA from dualE
Con#ersion &unctions
!o-Char --
to-char,number of date(AformatA
2f use to change or to con#ert number@Date to Character format( it is useually used to change from default
date format to alternate date formate.
select sysdate(to-char,sysdate(Add@mm@yyA from dualE
select sysdate(to-char,sysdate(Add month yearA from dualE
&+ ,&ill +ode --
2t can be used sub "lace reading zeros for ddth format.
select sysdate(to-char,sysdate(Afmday ddth mm yyA from dualE
0Ctraction %f !ime &rom Date
select sysdate(to-char,sysdate(A99:+2:SSA from dualE
select sysdate(sal(to-char,sal(A J<(<<<.<<A from em"E
.refiC SuffiC
---------- ----------
&+ th
S. S.th ,%R th S.
select sysdate(to-char,sysdate(A fm day dds"th yyA from dualE
!o-:umber --
to-number,char
Con#erts the number stored as character to number data ty"e.
select K from em" where sal -A6>>>A where sal - to-number,A6>>>A E
!o-date --
to-date, AcharA(A formatA
Con#erts the character #alue re"resenting date into date #alue according to format s"ecified( if format is
omited the date format is dd-mm-yy.
select hiredate(to-date,hiredate(Amonth-yy-ddA from em"E
select hiredate( to-date,hiredate(Amonth-s"ddth-yyyA from em"E
K !o "rint :o. of Days between the Current Date to Worth Date.
select sysdate-hiredate from em"E
select sysdate-to-date, A1>-$"r->6A from dualE
K !o "rint :o.of Days between to Dates.
select to-date,A 1>-$"r->/A (to-date,A 1>-Gul->6A from dualE
:umber &unctions
%"erators on numeric ty"e of data.
round, --
Syn:- round,no(no. of decimals
!o round the number to the s"ecific no of decimal "laceses. 2f no. of decimal is A>A no decimal "laces( no.
of decimal is -1. 2f no. of decimal is nagiti#e round the no. to the left of it.
0C :- select round,1)6.BD<6()( round,1)6.BD<6(round,1)=.BD<6(-1 from dualE
s'rt, --
Syn:- s'rt,no
Returns the s'rt of a no.
0C:- select s'rt,)8 from dualE
mod, --
Syn:- mod,no.1(no.)
2t has the remainder when first no. is de#ided is the second no.
0C:- select mod,)8(8()8@8 from dualE
abs, --
Syn:- abs,no.
Return the absulate #alues a no.
0C:- select abs,1>(abs,-1> from dualE
least, --
Syn:- least,no.1(no.)(...........
&ind the smallest of the noAs.
0C:- select least,/(B(6(D from dualE
#size, --
Syn:-
Returns the size of a "art a col or #alue.
"ower, --
Syn:- "ower,C(y
Ranges the no. to the nth "ower.
0C:- select "ow,)(6 from dualE
decode, --
Syn:- decode,col @ #alue( Afrom stringA ( Ato stringA L( AfromA( Ato A ( .....M( default
,%R
decode,col @ eC"r( search1(result(Lsearch)(result( .......M defaultM
0C:- select ?ob decode,?ob(Asales manA(AsaleswomanA(AmanagerA from em"E
-- Column %r 0C"ression is com"ared to each Search #alue and returns the #alue( if column %r
eC"ression e'uals the search #alue( if no match is found decode function returns the default #alue( if the
default #alue is omitted the null #alue is returned for unmatched #alues.
:ote :- Decode &unction is used as an alternate to 2f 0lse %r Case construct.
K W.$.4. !o re"lace all tabs with salesman as saleswoman( managers with eCcuti#e and others with
"ersons.
select ?ob(decode,?ob(AsalesmanA(Asales womanA(AmanagerA(A0CecA(A"ersonsA from em"E
K W.$.4. !o increase the salary baseing on Gob.
select ?ob(sal(decode,?ob(AC50RNA(salFsalK1.8@1>>( A+$:$70RA(salFsalK)@1>>(
ASalesmanA(salFsalK/@1>>(salFsalK6@1>> from em"E
length, --
Syn :- length,col @ #alue
!o calculate the 5ength of String.
0C :- select length,ename(length,A#ishnuA from em"E
Character &unction :-
concat, --
Syn :- concat,col1(col)
2t is used to concatenate of two strings.
0C:- select ename(?ob(concat,ename(?ob 0m"loyee from em"E
7rou" &unctions :-
!hese "rocess sets of rows.
sum, --
Syn :- sum,col
Returns the sum of #alues of column.
0C:- select sum,sal from em"E
maC, --
Syn :- maC,col
Returns the maC of #alues of column.
0C:- select maC,sal from em"E
a#erage, --
Syn :- a#erage,col
Returns the +ean of #alues of column.
0C:- select a#g,sal from em"E
min, --
Syn :- min,col
Returns the minimum #alues of column.
0C:- select min,sal from em"E
count, --
Syn :- count,col
Returns the count of #alues of column.
0C:- select count,em"no from em"E
K
0C:-
W.$.4. to Count :o.%f 0m"loyees wor3ing in a selected de"tno.
select count,K from em" where de"tnoI&dnoE
7rou" *y Class :-
2t is used to dis"lay the 'uery result into small of grou"s. +ainly this class is used on the column whose
#alues are re"eated.
Syn :- select K L ,col1(col)( .....M from Otable name- grou" by ,col1( col)( ....E
K
0C :-
W.$.4. to find the maC sal with ?ob wise.
select ?ob( maC,sal from em" grou" by ?obE
W.$.4. to count the no. of em"loyees de"tno wise.
select de"tno(count,K from em" grou" by de"tnoE
9ar#ing Clause :-
har#ing clause restructs the set of rows where as where clause restructs indi#idual course.
Syn :- select K L ,col1(col)( ....M from Otable name- har#ing cond,sE
K
0C:- W.$.4. to dis"lay the de"artment noAs em"loyeed more than two em"loyees.
select de"tno(count,K from em" grou" by de"tno har#ing count,K - )E
0C:-
select ?ob(maC,sal from em" where ?ob PIA +$:$70RA grou" by ?ob.
0C:- W.$.4. to chec3 whether em"no is indeed uni'ue.
select em"no(count,K from em" har#ing count,K - 1 grou" by em"noE
Sub 4ueries :-
select statement with in another select statement.
Syn :-
select column,s from Otable name- where col I ,select stat. E
.rocessing --
&irst of all inner 'uery is eCecuted and then outer 'uery is eCecuted by tab3ing the result of inner 'uery as
the condition for outer 'uery.
0C:-
W.$.4. to dis"lay the name of em"loyee maC salary.
select ename from em" where sal I ,select maC,sal from em"E
K
W.$.4. to find the name of em"loyee( when get second maC salary.
select ename from em" where sal in ,select maC,sal from em"
where sal not in,select maC,sal from em"E
G%2:S
0Ctraction data from more than one table. 2t is a horizantal Goin ,row wise. Goins is / !y"es.
1 0'uiGoin ) :on-0'uiGoin / %uterGoin 6 Self Goin
1 0'ui Goin --
!he relation between em" and de"t table is e'ui?oin. !hat is both are tables are ha#ing the same column
called de"tno on which e'ui?oin relationshi" can be establish using A I A o"erator.
Syn:-
select K L,col1(col)( ..... from Otable,s- where ?oin cond,sME
0C:-
select K from em"(de"t where em".de"tnoIde"t.de"tnoE
select em"no(ename(?ob(sal(em".de"tno(dname(loc from em"(de"t where
em".de"tnoIde"t.de"tnoE
Q
0rror
------------------------
$s de"tno column is a#ailable in both the tables error is encounter( because it is enable to understand
from which table the #alue as be eCtracted from( when e#er there is common field are a#ailable in both
the tables s"ecify the field name( colunm by the table name A . A the field name.
!able 0lyasis --
Reffering a table with an alternet name a#aiding re"etating to ty"ing( which can be u"to /> characters in
length( but less than better.
select em"no(ename(?ob(sal e.de"tno(dname(loc from em" e( de"t d where e.de"tnoId.de"tnoE
Rules for Goining Condition --
1 no. of tables -1 I Goin condition
:on0'ui Goin --
0C:- dis"lay the salary with lowest sal & high sal
select ename( ?ob( sal( losal( hisal from em" e( salgrade s where e.sal between s.losal and s.hisalE
%uter Goin --
!he outer ?oin is to add the one to another table of records with use the A F A o"erator.
0C:-
select ename( ?ob( sal( e.de"tno( dname from em" e( de"t d where e.de"tno ,F I d.de"tnoE
Self Goin --
Goining a table using itself table elyasis as it two tables se"arator.
0C:-
select e.ename em"name( e.sal em"sal( m.ename mgrname( m.sal mgrsal from em" e(em" m e.mgr I
e.em"noE
Set %"erators :-
!hese are many use to combine the results of two 'uries into one.
1nion --
Dis"layes the result "resent is first 'uery another second 'uery eCcluding du"licate rows.
select ?ob from em" where de"tno I 1>
union
select ?ob from em" where de"tnoI/>E
1nion all --
Same as abo#e but including du"licate rows.
select ?ob from em" where de"tno I 1>
union all
select ?ob from em" where de"tnoI/>E
2ntersect --
Returns are rows which are common in both the 'ueries.
select ?ob from em" where de"tno I 1>
intersect
select ?ob from em" where de"tnoI/>E
+inus --
Returns the rows which are their in first but not "resent in second.
select ?ob from em" where de"tno I 1>
minus
select ?ob from em" where de"tnoI/>E
S45 .lus Commands
Sa#e --
sa#e Ofile name-
Sa#e the contains of the s'l buffer on to the s"ecified with an eCtension . s'l
5oad --
load Ofile name-
!o load the contains of s"ecified file on to the buffer and eCecute same and "ressing slash , @ .
Start --
start Ofile name-
%R
R Ofile name-
5oads the contains of s"ecified file on to the buffer and or eCecuted automatically.
0d --
ed Ofile name-
!o create a new file or o"en the eCisting file from modification. Default editor is note"ad.
S45 *uffer Commands
5 -- !o list the contains of the buffer.
5, -- !o list the s"ecified line number.
5 ,no
c -- !o change the teCt
Syn:- c @ old @ new
0C:- c @ em" @ de"tE
S45 .lus Commands
0Cit -- !o eCit from S45 .lus
Connect -- !o connect a oracle user.
Syn :- connect username @ "assword R connect-stringE
Show 1ser -- Dis"lays the current user.
Set Commands
!hese are used to control the wor3ing en#ironmental of s'l "lus. !he set command that set or acti#e as
non as the system is 3now. !o ma3e the acti#e all the time include these comands in a s"ecial file login
s'l. Which is in#o3ed e#ery time s'l "lus is run.
login S'l -- !his is only system file.
Set $utoCommit %n @ %ff --
Default is %ff. 2f it is on the changes that are made or commited automatically without using command
commit eC"licitly. 2t is %ff the changes are made "armenent only of the issuing command commit
im"licitly.
Set 5ineSize --
set linesize Ono-
Sets the no.of characters access a line.
set linesize 1)>
Set 9eading %n @ %ff --
Default is %n. 2f it is %ff su""ress the column headings.
Set .ause %n @ %ff --
Default is %ff. 2f it is %n it "rom"t the user( to "ress any 3ey to continue.
Set .agesize --
set "agesize Ono-
Sets the no.of line accross a "age.
Set &eed*ac3 %n @ %ff --
Default is %n. 2f it is %ff the message regrading the command that is "rocess is su"ressed in the dis"lay.
Set ;erify %n @ %ff --
Default is %n. 2f it is %ff the #alue that is su""lied using su""ression #alue is not #erify to the eC"ression.
0C:-
select K from em" where ename I A&nameAE
select K from em" where ename I ASC%!!AE
Set Ser#erout %n @ %ff --
Default is %ff. 2f on dis"lays the message on the screen while wor3ing with .5@S45 using message
command.
Set :um&ormat
set numformat Aformat A
Set the s"ecified no. format which is a""licable for all the numeric columns of a table.
0C:-
set numformat <(<<<.<<
select em"no(de"tno(sal(comm from em"E
;ariables in S45@.lus
Whose #alue 3ee"s going on changing. !here is two ty"es.
1 Substitution ;ariable ) *ind ;ariables
Substitution ;ariable -- Substitution ;ariable is two ty"es.
a Single Substitution ;ariable b Double Substitution ;ariable
*ind ;ariables -- *ind #ariable are the #ariables declared in other host en#ironment and can be reffered
in .5@S45 by : #arE
Single & Substitution ;ariable --
When it is used it "rom"ts the user to enter the #alue at run time( and the #alue that is entered is not
stored or sa#ed into the #ariable( hence it allows the user to enter the new #alue each time the 'uery is
eCecuted to "ressing A @ A.
:ote:-
character and date #alues should be enclosed in single 'utotion mar3s and the noAs need not.
0C:-
select K from em" where em"noI&enoE
select K from em" where ename IA&nameAE
0ntering the Condition $t Run !ime --
select K from em" where & condE
0nter the #alue of cond : 0name I ASC%!!AE
Gob I A+$:$70RAE
K
W.$.4. to enter the column names to eCtracted from a table at run time.
select &col1(&col)(&col/ from em"E
select &col1(&col)(&col/ from &tablenameE
Double && Substitution ;ariable --
2t allows the user to enter the #alue at runtime when the 'uery is eCcuted for first time. !he #alue that is
entered is stored in the #ariable( hence each time the 'uery is eCecuted the "ressing A @ A 3ey the result is
dis"layed with the same "re#ious #alue.
select K from em" where ?ob I A&&desig AE
Define Command --
2t is used to define a #ariable or list the #ariables that are defined.
:ote:-
*y default the #ariable that are defined using define command are always ty"e character.
K
W.$.4. to calculate the annual salary of em"loyee.
:ote :-
!o reffer a #ariable in s'l statement s"ecify the #ariable name "ressed by single & .
0C:-
define annsal I sal K 1) F :;5,comm(>E
select ename(?ob(sal(comm(&annsal from em"E
1ndefine --
!o undefine a #ariable use the command undefine followed by the #ariable name.
Syn:-
undefine O#ar-
0C:- undefine annsalE
$cce"t Command :-
2t is used to declare a #ariable of s"ecified dataty"e.
Syn:-
acce"t O#ariable- Odata ty"e- L"rom"tM Lno "rom"tM LhideM
0C:-
acce"t msal numberE
Define -- to list the memory #ariable.
Refferring the memory #ariables in select statement --
select &msal from dualE
.rom"t -- .rom"ts the user with user defined message.
0C:-
acce"t msal number "rom"t A 0nter Salary A
9ide -- 9ides the #alue from dis"lay( each character that is ty"e is dis"layed with an astric3 ,A K A
0C:-
acce"t "rod #archar) "rom"t A 0nter .assword A hide
S45 .lus Re"orts
Re"orts -- 0Ctracting of data from a database ,table & "rinting it in a format.
Re"ort 5ay%ut
1 .age 9eader -- 7ets "rinted at the to" of each & e#ery "age.
) .age &ooter -- 7ets "rinted at the bottom of each & e#ery "age.
/ Detail *ound -- 7ets "rinted for each & e#ery record.
Data 7rou"ing -- 7rou"ing of data
1 %n a column( whose #alues are re"eated.
) $rrange the data in the order of grou"ing column.
$dditional *onds :-
1 7rou" 9eader -- is "rinted at the to" of each grou".
) 7rou" &ooter -- is "rinted at the end of each grou".
Column Command :-
2t is used to s"ecified the format s"ecification on the column dis"lay.
Syn:-
column Ocolumn name- format Oformat- heading Oheading-
&ormat -- is acce"t character or number ty"e. Character is acce"t - a( number is acce"t - <.
0C:-
1 column em"no format <<<< heading A0m" :oA.
) column ename format a18 heading A0m" :ameA ?ustify right Q
/ column ?ob format a1> heading ADesignationA ?ustify center.
6 column sal format <<(<<<.<< heading ASalaryA
8 column comm format <(<<<.<< heading ACommissionA :155 A:o commA
B column de"tno format << heading ADe"t :oA
select em"no(ename(?ob(sal(comm(de"tno from em"E
!!itle & *!itle Commands :-
!!itle --
Syn:- !!itle A teCt A
2s used to dis"lay the "age no. to wards the right side column and date u""der left side cornor and teCt
that is s"ecified used !!itle command is dis"layed in the center of the neCt line.
0C:-
!!itle A0m"loyee DetailsA
*!itle --
Syn:- *!itle AteCtA
Dis"lay the s"ecified teCt at the bottom line of the "age centered.
0C:-
*!itle A 0nd of the Records A
select em"no(ename(?ob(sal(de"tno from em"E
!!itle @ *!itle L%ff M :-
!!itle off -- to remo#e the to" title.
*!itle off -- to remo#e the bottom title.
Clear Column -- to clear the columns
*rea3 %n Re"orts ,Data 7rou"ing :-
*rea3 command is used to brea3 the re"ort into smaller grou"s.
Syn:-
*rea3 on Ocolumn-
0C:-
brea3 on de"tnoE
select de"tno(em"no(ename( ?ob(sal from em" order by de"tnoE
Summary Calculations :-
Summary calculations can "erform using com"ute command.
Syn:-
com"ute Oclause- of Ocolumn,s- on Ocolumn- Lon re"ort M
0C:-
com"ute sum a#g of sal(comm on de"tnoE
Data Definition 5anguage Commands ,DD5
/ ty"es of DD5 commands
1 Create ) $lter / Dro"
Create --
2t is used to define the structure of a table.
Syn:-
create table Otable name- , col1 dataty"e,size( col) dataty"e,size ...... coln dataty"e,sizeE
Data !y"es :-
Determines what ty"e of data a #ariable.
Char -- &iCed character length of width ( default is 1( the maCimum is )88 characters.
#ersion =.>> - )88
#ersion D.>> - )>>>
;archar) -- ;ariable character length of width( maCimum is )>>> in =.>> & 6>>> is D.>>.
Date -- !o store date and time #alues.
5ong -- Same as ;archar)( but can store to a maCimum length of ) 7*( only column should eCist with
ty"e long.
5ong raw @ raw -- same as long( but stores gra"hic images.
:umber -- 2t acce"t "uerly noAs of decimals of width( maCimum of /D digits.
:umber ,w(s -- Store the no. width w( and scale ,"recesion of s.
Data +ani"ulation 5anguage Commands ,D+5
1 2nsert ) Delete / 1"date
!hese are used to mani"ulate the data.
2nsert -- !o insert the rows into a table.
Syn:-
insert into Otable name- L,col1(col)(col/( ...... ( colnM #alues ,#al1(#al)(#al/ ........ #alnE
-- 5ist of #alues s"ecified should be e'ual the no.of columns s"ecified and should match in the order(
dataty"e.
0C:-
insert into std,rno(name #alues,1(AshAE
insert into std #alues,1>(AshA(A )>-Gan->6A E
-- Date and Character #alues should enclosed single codes.
0ntering the Date in alternat format other than a default format.
insert into stud #alues,1>>(AshA(todate, A Gan-)>->6A(A +on-dd-yyA E
2nserting !ime --
0C:-
insert into stud #alues,)>>(AshA( todate, A Gan-))->/ 1>:/> A(A mon-dd-yy hh:minA E
insert into stud #alues,&rno(A&nameA(A&dateA E
Delete -- !o delete the records on to selected table( 2f where condition is used the selected records are
deleted.
Syn:-
delete from Otable name- Lcond.ME
0C:- delete from stud where rno -1>E %R delete from stud where rnoI1>E
1"date -- !o u"date the column #alues of a table.
Syn:-
u"date Otable name- set col I #alue @ eC"r L,col)I#alue @ eC"r( ......M Lwhere condME
0C:-
u"date em" set enameIAshA ( sal I salF1>>> where hiredateIA )>-&eb->6AE
Demobld -- !o build the demo tables.
0C:- RdemobldE
!ransaction .rocessing Commands
Commit -- !o sa#e the changes "erminently.
Roll*ac3 -- !o 1ndo %R Cancelled the changes are made.
Sa#e .oint --
Sa#e "oint indentifies the "oint transaction to which one can latter rollbac3 with rollbac3 statement. 2t is
hel"ful in the transaction contains large no.of S45 statements and the user wants to Commit only oneAs.
2t re'uired the user can Rollbac3 it a "articular transaction.
Syn:-
sa#e"oint Oname-
Rollbac3 to Sa#e "oint name --
1ndo the canges u"to the sa#e"oint.
Syn:-
rollbac3 to Osa#e"oint name-
0C:-
1 insert into de"t #alues,6>(A A(AteCasA E
) sa#e"oint CE
/ u"date de"t set dnameIAabcAE
6 rollbac3 to CE
-- Rollbac3 statement will 1ndo( only the 1"dation. $ll the satements before the sa#e"oint ACA( remain
unchanged.
Dro" Command --
!o dro" the tableE
Syn:-
dro" table Otable name- LcascadeME
-- Cascade o"tion is used to dro" the refferential integrity constraint.
D55 Commands
2ntegrity Constraints :-
!hese are used to infource to a certain rolls with in a table or between the table.
-- !he character the date #alues can be left blan3( by s"ecify null %R a s"ace( and numeric #alues tih
null.
!y"es of 2ntegrity Costraints -- two ty"es.
1 Column Constraints ) !able Constraints
1 Column Constraints -- Column constraints of a defined of a column along with a definetion of column.
) !able Constraints -- !able constraints are define outside the definetion of a columns.
!able @ Column Constraints :- / ty"es
1 Domain 2ntegrity Constraints --
Chec3
) 0ntity 2ntegrity Constraints --
.rimary Ney( 1ni'ue( :ot :ull
/ Referential 2ntegrity Constraints --
&oreign Ney
1ni'ue --
2nsures the uni'ueness on that #alues in a column( that is not two rows in the table should ha#e the same
column #alue.
-- 1ni'ue constraint is used du"licate #alues are not acce"ted( but null #alues are acce"ted.
Syn:-
Lconstraint Oconstraint name-M 1ni'ueE
0C:-
create table stud,rno number,/ constraint conroll 1ni'ue( name #archar),1>E
!able Constraints --
2t is used to set the same Constraint +ore than %ne Column also.
Syn:-
( Lconstraint Oconstraint name-M 2ntegrity Constraint ,col1(col)( ........E
0C:-
create table stud,rno number,/(name #archar),1>( constraint rnacon 1ni'ue,rno(nameE
-- !he !able Constraints is used !o Chec3 !he Constraint Columns %f !he ;alues is 0'ual 2t Will :ot
$cce"t( Whether( $ny %ne Column 2s :ot 0'ual 2t Will $cce"t !he Records.
:ot :ull Constraint --
:ot :ull constraint is used :ull #alues are not acce"ted( but Du"licatel #alues are acce"ted.
Syn:-
Lconstraint Oconstraint name-M :ot :ullE
0C:-
create table stud,rno number,/ constraint conroll :ot :ull( name #archar),1>E
Chec3 Constraint --
Chec3s for the correctness of the #alue enter with the hel" of acondition.
Syn:-
Lconstraint Oconstraint name-M Chec3,condE
0C:-
create table stud,rno number,/ constraint conroll Chec3,rno-8>( name #archar),1>E
create table stud,rno number,/ constraint conroll Chec3,rno-8>( name #archar),1> constraint
nacon
chec3,name I 1""er,nameE
-- 2t will $cce"t Du"licates & :ull #alues( but it will chec3 the Condition.
.rimary Ney --
2t 0nfources the entering of Du"licate and :ull ;alues.
-- We can ha#e only one .rimary Ney column for a table.
Syn:-
Lconstraint Oconstraint name-M .rimary Ney
0C:-
create table stud,rno number,/ constraint conroll .rimary Ney( name #archar),1>E
Referential 2ntegrity Constraints :-
&oreign Ney --
2t is a combination of columns with #alues where the .rimary Ney #alues from another table.
$ &oreign Ney constraint with is also 3now as referential integrity constraints with the s"ecifies the #alues
of &oreign Ney corres"oned to actual #alues at the .rimay Ney in $nother !able.
-- &oreign Ney is used to 0stablish .arent and Child Relationshi" *etween the !ables.
Syn:-
Lconstraint Oconstraint name-M references Otable name- ,colE
-- !o ha#e the Relation *etween of Columns of same !able.
0C:-
create table stud,rno number,) .rimary Ney(
name #archar,1> constraint rnocon references stud,rnoE
!able Constraint --
Syn:-
( Lconstraint Oconstraint name-M &oreign Ney ,col LcascadeM references Otable name- ,colE
0C:-
.arent
create table ",rno number,/ .rimary Ney( name #archar),1>E
Child
create table ',rno number,/( name #archar),1>(
constraint frno &oregin Ney,rno references ",rnoE
:ote :-
1 &irst 2nsert the :ew Rows into .arent !able and then into Child !able
) &irst Delete the Rows into Child !able and then .arent !able.
Cascade %"tion --
2f Cascade is included the cors"oned records of Child !able( and it will be Delete %R 1"date the Child
!able of Rows it will be change into the .arent !able.
0C:-
Child
create table ',rno number,/( name #archar),1>(
constraint frno &oregin Ney,rno references ",rno cascadeE
$lter --
!o Change the defination of a Column. 5i3e Column !y"e and Size( but Column :ame not Change.
Syn:-
alter table Otable name-
add @ modify @ dro" , col1 dataty"e,size L2ntegrity ConstraintM ..... Lenable @ disableME
$dd -- !o add the Column on to the eCisting table.
+odify -- !o modify the select Column of Dataty"e & Size.
!o modify the table of columns( before changing ma3e sure that no rows eCisting in the table.
0C:-
alter table stud add, name #archar),18E
alter table stud add constraint rnocon .rimary Ney ,rnoE
alter table stud modify name #archar),)>E
Dro" Clause --
!o Dro" a Constraint.
Syn:-
alter table Otable name- dro" ,2ntegrity constraintE
0C:-
alter table stud dro" "rimary 3eyE
alter table stud dro" constraint rnoconE
5ist of Constraints --
select K from 1ser constraintsE
0nable %R Disable Clause --
!o ma3e the constraint %n @ %ff without dro""ing %r recreating.
Syn:
alter table Otable name- 0nable @ Disable ,2ntegrity ConstraintE
0C:-
alter table stud disable "rimary 3eyE
-- 2f Disable the constraint column( the constraint column will acce"t the du"licate #alues and null #alues.
alter table stud enable "rimary 3eyE
-- 2f enable the constraint column( the constraint column will not acce"t the du"licate #alues and null
#alues.
Dro" Command --
!o Dro" a !able.
Syn:-
dro" table Otable name- LcascadeME
-- Cascade o"tion is used to dro" the refferential integrity constraint.
!runcate Command --
Same as Dro" Command( but changes made cannot be cancelled.
Rename -- !o changes the name of a !able.
Syn:-
rename table Oold- as @ to Onew-
Data Control 5anguage Commands
1 7rant ) Re#o3e
D*$ ,Database $dministrater --
is res"onsible for creating new users( granting of "ermissions etc.(.
2tAs a %wner of %racle Database.
1 Creation of new 1ser --
Syn:-
create user Ouser name- identified by O"assword-E
0C:-
S'l-create user #i#a identified by madhuE
Changing of .assWord --
Syn:-
alter user Ouser name- identified by O"ass word-E
0C:-
S'l-alter user #i#a identified by #ishnuE
Show 1ser --
Dis"layes the currently logged 1ser.
Connect --
!o Connect another %racle 1ser from the Current 1ser.
Syn:-
Connect username @ "assword RconnectstringE
0C:-
S'l-connect #i#a @ #ishnuRorclE
Show 1ser
7ranting of .ermissions @ D*$ :-
1sing 7rant Command --
) 7rant connect( resource to #i#aE
System .re#ilegies :-
i Create Session --
!o get connect to the database.
ii Create !able --
!o create a table.
iii Create ;iew --
!o create a #iew.
Create 1ser --
!o create a user.
Role -- Collection of "re#iliges.
Connect -- Collection of a boC "re#iliges.
/ Connecting to :ew 1ser --
connect sh @ sh1)/RorclE
6 *uilding of Demo!ables --
0C:-
RdemobldE
8 7ranting of .ermissions .re#iliges on an %b?ect to a 1ser --
.re#iliges --
select -- to select the data
delete -- to delete the data
u"date -- to u"date the data
insert -- to insert the data
indeC -- to create an indeC
#iew -- to create an #iew
all -- all of the abo#e.
Syn:-
grant "re#iliges ,on table @ #iew to user,sE
0C:-
grant select on em" to shE
grant select( u"date on em" to shE
grant u"date on de"t,dname to shE
grant all on em" to shE
Re#o3e --
!o ta3e bac3 the "re#iliges gi#en to another user from user.
Syn:-
re#o3e "re#ilige,s on table @ #iew from Ouser-E
0C:-
re#o3e delete on em" from CyzE
Synonames
!o access the table of another user table name should be followed by the user name with the dot,..
0C:-
select K from scott.CyzE
2nstead of reffering of a table own by another user by saying user name( table ( a synonymn can create
on a table own by another user.
Syn:-
create synonym Osynonym name- for Ouser.table-
0C:-
create synonymn C for scott.em"E
select K from CE
Database %b?ects
Se'uence --
2t is used to generate the noAs in a se'uence.
Syn:-
create se'uence Ose'uence name-
increment by Ono-
start with Ono-
maC#alue @ no maC#alue
min#alue @ no min#alueE
0C:-
create se'uence nose'
increment by 1
start with 1
maC#alue )>E
:eCt #al --
2t is a suit of col used with the se'uence to reffer the neCt #al of se'uence.
0C:-
select nose'.neCt#al from dualE
Cur#al --
2t is a suit of column used to reffer the current #alues of se'uence.
0C:-
select nose'.cur#al from dualE
:ote :-
1 Se'uence is main used to generate the noAs of se'uentially which a#aids the du"licates #alues of null
#alues.
) 2t is main used to insert command to insert the rows into a table.
0C:-
insert into C #alues,nose'.neCt#alE
$ltering the Se'uence --
1sing $lter Se'uence command.
Syn:-
alter se'uence Ose'uence name-
increment by Ono-
maC#alue @ no maC#alue
min#alue @ no min#alueE
:ote :-
1 Start with #alue canAt be alter.
) %neAs the se'uence is alter it is go to se'uence that is to be generated of the altering.
0C:-
alter se'uence nose'
increment by 8
maC#alue 1>>E
Dro"ing of Se'uence --
Syn:-
dro" se'uence Ose'uence name-
5isting of Se'uences --
userSse'uences
select K from userSse'uencesE
2ndeC --
the 'uery using where clause on the column on which table is indeCed.
!y"es of 2ndeCes --
uni'ue
nonuni'ue ,default
concatenated
Syn:-
create Luni'ueM indeC OindeC name- on table ,col1(col)( ....E
2ndeCes --
1 default is non-uni'ue
a create indeC ind on em",enameE
b select K from em" where enameIASC%!!AE
) 1ni'ue-2ndeC --
2t is created automatically when a uni'ue constraint is defined on a table. Which entries the 1ni'ue
#alues are a#ailables. that is no two rows in the table should ha#e same #alue.
0C:-
create table C,no number,) uni'ueE
:ote :-
1ni'ue indeC is created automatically( when a uni'ue constraint is defined on a column a#oiding du"licate
entries.
Creation of 1ni'ue 2ndeC
1 create table C,no number,/E
) create uni'ue indeC ind on C,noE
/ insert rows into C tables du"licate #alues are a#oided as uni'ue indeC is created on no.
Concadinated 2ndeC --
2ndeC on more than one column.
0C:-
created indeC id on em",ename(?obE
:ote :-
2t has the effect only when multi"le rows ha#e same #alue.
Dro"ing %f 2ndeCes --
Syn:-
dro" indeC OindeC name-
5isting of 2ndeCes --
select K from userSindeCE
;iews
$ #iew is li3e a window to which data on tables can be #iew.
$ #iew is deri#ed from other table or #iew( which is reffered as the base table of the #iew. $ #iew is
through as select statement only( and it is #irtual table( that is a table that not eCist "hysically( but u""ears
to the user as a eCist.
$ #iew as no data of itAs own but it mani"ulates the data in the underline based table.
!y"es :-
1 Sim"le ;iew --
Deri#ed data from only one table and contains no functions or nosub data.
) Com"leC ;iew --
Deri#ed from any tables and contains functions or grou"s of data.
Create ;iew --
Syn:-
create Lor re"laceM LforceM #iew O#iew name- L,col1(col)( .......M as select statementE
1 Sim"le ;iew --
0C:-
create #iew em"#iew as select K from em"E ,%R
create #iew em"#iew,no(name(desg as select em"no(ename(?ob from em"E
select Kfrom em"#iewE
delete from em"#iew where de"tnoI1>E
insert into em"#iew,em"no(ename(?ob(de"tno #alues,1>>(AabcA(AmanagerA()>E
Com"leC ;iew --
create #iew em"de"t,de"tname(minsal(maCsal(a#gsal as select
dname(min,sal(maC,sal(a#g,sal
from de"t(em" where de"t.de"tnoIem".de"tno grou" by dnameE
Re"lace --
2t allows the #iew is created e#en if the #iew is eCistable in the same name( re"laceing the old#ersion of
the #iew.
create or re"lace #iew em"#iew as select K from em"E
&ource --
!his o"tion allows users create a #iew e#en( if the base table does not eCist or if there are insufficiant
table( for the table must be eCisted by using the #iew.
0C:-
create force #iew em"#iew as select K from em"E
5isting of ;iew --
userS#iews
select K from userS#iewsE
Dro"ing a ;iew --
dro" #iew O#iew name-E
PL / SQL
.rocedure 5anguage @ Structured 4uery 5anguage.
2t is an eCtension to S45 incor"orating the feature of other "rogramming languages li3e *inary
Statements( Decimal +a3ing 5oo"ing Constructs &unctions etc(.
Advantages:-
1 ;ariables -- &or storing the mani"ulating the #alues dataty"es includes( dataty"es a#ailable in S45
.lus dataty"es.
) S45 Su""ort -- Select( 2nsert( Delete( 1"date( Commit( Sa#e"oint( Roll*ac3 are su""orted.
/ Com"osite Dataty"es -- Records allowed grou"s of fields to be defined and mani"ulated in .5 @ S45.
i Record ty"e #ariables.
ii Column ty"e #ariables.
6 &low of Control -- 2f Statement( 5oo"s( 7oto( 5abels( "ro#ides condition access branching iterati#e
control with "rograms.
8 *uilt-2n-&unctions -- Same as that of S45( but 7rou" &unctions are not su""orted( but su""orts two
eCtra functions for error tra""ing
S45 Code
S45 0rror
B Cursors -- 2s an 2dentifier for a memory location.
= 0Cce"tion 9andling -- Warning and eror conditions are defined as eCce"tions which can be handled in
each bloc3. 0Cce"tion 9andlers s"ecify what has to be done
when the error is encountered.
Structure Of PL / SQL Blc!
Declare
--
--
--
Declaration StatementE
*egin
0Cecutable StatementsE
--
--
--
0Cce"tion
0Cce"tional 9andlersE
0ndE
"#$es Of Blc!s :-
1 $nanymous -- ha#ing no name
) Stored @ :amed *loc3s -- &unctions & .rocedures
Comments :-
1 --- , Single 5ine
) Set %f 5ines , TK KT
Data Re"resentation :-
;ariable & Constraint
;ariable are used to store data #alues.
Data !y"es :-
1 :umber --
) Character -- +aC of )88 characters.
/ ;archar) -- /)(=B= +aC ,S45 )>>>
6 Date --
8 *oolean --
Declaration %f ;ariables :-
!hese are declared in the declared section of the bloc3.
Syn :-
identifier dataty"eL,"recession ( scaleM :I #alue @ 0C"E
:I -- assignment o"erator
0C:-
name #archar),1>E
$ssignment %f ;alues ,%r ;ariable to a ;ariable :-
1 $t time of declaration
name #archar),1> :I A#ishnuAE
) $fter Declaration
name #archar),1>E
begin
name :I A#i#aA E
Declaration %f Constraint :-
#alues of the fiCed.
0C:-
"i constraint number,<(8 :I /.16=E
Select Statement 2n .5 @ S45 :-
Select statement is used in .5 @ S45 with into class( select statement should return only one row.
Select statement returning no rows or more than one row encounters an error. !o a#oid the said "roblems
eCe"ressions a#oid the raised.
Syn:-
Select col1(col)(...... into #ar1(#ar)(.......... from tableE
Errrs:-
no :- no data found -- if select statement is not returning any row.
-- 0Cact fetch returns
regreted more rows to be encountered.
!he column selected should be e'ualt to be no. of #ariables into which the #alues are "o"ulated and
should match in the order number and ty"e.
%r&t&ng r PL/SQL Blc!s:-
Anan#'us Blc!s :-
1 Writing of .5 @ S45 bloc3
Statement,s at S45 "rom"t which are stored in S45
declare
---
---
begin
---
---
endE
) Writing of .5 @ S45 bloc3s statements in Scri"t.
0C:-
S45 - 0d Ofilename-
-- getting the contents of the scri"t file onto buffer.
S45 - R Ofilename-E
-- 0Cecution
S45 - @
S45 - Set Ser#erout %n
-- !o Dis"lay !he Result.
" Pr&nt Message On "(e Screen:-
dbmsSout"ut."utSline ,A +essage .rom"t AE
dbmsSout"ut."utSline ,AResult is AE
dbmsSout"ut."utSline , c E
dbmsSout"ut."utSline ,AResult is A QQ cE
0C:-
S45 - ed a
1
declare
mname #archar),1>E
m?ob #archar),1>E
msal numberE
begin
select ename( ?ob( sal into mname( m?ob( msal from em" where em"no I &noE
dbmsSout"ut."utSline ,A0m" :ame AQQmnameE
dbmsSout"ut."utSline ,A0m" ?ob A QQ m?obE
dbmsSout"ut."utSline ,A0m" sal A QQ msalE
endE
) Sa#e & 0Cit -- $lt F &6
/ R aE
S45 - @
Declarat&n f clu'n "#$e )ar&a*le:-
1sing U ty"e attribute.
!he selected column information is to be "o"ulated into a #ariable which is com"atable no of to whole of
selected column with same size and ty"e.
S#n:-
identifier table.columnname U ty"eE
2f their is any error occurs. !o a#oid the abo#e "roblem U ty"e attribute is used.
Declarat&n Of Recrd "#$e )ar&a*le:-

U Rowty"e attribute.
Recording .5 @ S45 holds all the column names with their #alues with same ty"e and size.
S#n:-
recordname table U rowty"eE
0C:- erec em"Urowty"eE
-- !o access the column #alue for the record
recordname.columnnameE
0C:- erec.salE
declare
mname em".enameUty"eE
m?ob em".?obUty"eE
msal em".salUty"eE
select ename into mnameE
select ?ob into m?obE
select sal into msalE
%R
erec em"Urowty"eE
begin
select K into erec from em" where em"no I &noE
dbmsSout"ut."utSline,A0m" :o A QQ erec.em"noE
dbmsSout"ut."utSline ,A0m" :ame AQQerec.enameE
dbmsSout"ut."utSline ,A0m" ?ob A QQ erec.?obE
dbmsSout"ut."utSline ,A0m" sal A QQ erec.salE
endE
@
DML C''ands +n PL / SQL:-
Delet&n Of Recrd :-
declare
no numberE
begin
delete from em" where em"noI&noE
dbmsSout"ut."utSline,Arecord are deletedAE
endE
@
U$date Of Recrd:-
begin
u"date em" set enameIA#ishnuA
where em"noI&noE
dbmsSout"ut."utSline,Arecord are u"datedAE
endE
@
+nsert&n Of Recrd :-
begin
insert into em",em"no( ename( ?ob( de"tno #alues ,1>>(A#ishnuA(AstudA(/>E
dbmsSout"ut."utSline,A record is inserted AE
endE
E,ce$t&ns :-
2f any ty"e of eCce"tion is raised control is "assed to the eCce"tions section of the bloc3 in which the
eCce"tion occured. 2t the eCce"tion is not handled their or if there is no eCce"tion section at all that the
bloc3 terminated without unhandled eCce"tion. !o tra" such e#ents or a#oidings the bloc3 terminating
without handling the eCce"tion( eCce"tion handlers may be defined in the eCce"tion section of the bloc3.
S#n:-
when eCce"tion handler then actionsE
"#$es Of E,ce$t&ns :
1 .redefined eCce"tion ) 1ser defined eCce"tion
1 .redefined 0Cce"tion --
!hese are defined by .5 @ S45 and are raised im"licitly associated with s"ecific error messages.
) 1ser defined 0Cce"tion --
!hese are defined by the user in the declare section of bloc3 as normal #ariables and are raised eC"licitly.
Predef&ned :-
1 :oSDataS&ound --
2t is raised when the select statement is not returning at a row.
Raising of eCce"tion when
,eCce"tion handler then
section.
0C:-
declare
erec em"Urowty"eE
begin
select K into erec from em" where em"noI&noE
dbmsSout"ut."utSline,A 0m":o A QQ erec.em"noE
dbmsSout"ut."utSline,A 0m":ame A QQ erec.enameE
---
---
eCce"tion
when noSdataSfound then
dbmsSout"ut."utSline,A Record is not eCisted A E
endE
@
) !ooS+anySRows --
2t is raised when the select statement is returning more than one row.
Syn:-
when tooSmanySrows then
dbmsSout"ut."utSline,A more than one row is returnedAE
endE
0C:-
declare
erec em"Urowty"eE
begin
select K into erec from em" where em"noI&noE %R select K into erec from em" where
de"tnoI&dnoE
dbmsSout"ut."utSline,A 0m":o A QQ erec.em"noE
dbmsSout"ut."utSline,A 0m":ame A QQ erec.enameE
---
---
eCce"tion
when tooSmanySrows then
dbmsSout"ut."utSline,A !oo +any Records A E
endE
@
/ Du"S;alS%nS2ndeC --
2s raised when the record is inserted in a table with du"licate #alue of a column constrained by a 1ni'ue
2ndeC.
a create table C ,
rno number,) uni'ue(
name #archar),1>E
b
declare
begin
insert into C #alues ,1(AsanthoshAE
eCce"tion
when du"S#alSonSindeC then
dbmsSout"ut."utSline,A record must be uni'ue A E
endE
@
6 ;alueS0rror --
2s raised when the column size is not sufficient to hold to "o"ulated column #alue.
0C:-
a create table C,
rno number,)(
name #archar),1>E
b
declare
erec CUrowty"e
begin
insert into C #alues ,1>>(AsanthoshAE %R insert into C #alues,&rno(A&nameAE
dbmsSout"ut."utSline,A Rno A QQ erec.rnoE
dbmsSout"ut."utSline,A :ame A QQ erec.nameE
eCce"tion
when #alueSerror then
dbmsSout"ut."utSline,A size of the column is not sufficientA E
endE
@
8 %thers --

2s raised when the column is 2n#alid Data!y"e.
0C:-
declare
begin
insert into em",em"no(ename(de"tno #alues ,1>1( Cyz(1>E %R insert into
em",em"no(ename(de"tno #alues ,&em"no(&ename(&de"tnoE
eCce"tion
when others then
dbmsSout"ut."utSline,A 2n#alid dataty"e ... :o records inserted A E
endE
@
B VeroSDi#ide --
2t is raised when the di#isor I >
0C:-
declare
msal em".salUty"eE
begin
select sal @ > into msal from em" where em"noI&noE
eCce"tion
when zeroSdi#ide then
dbmsSout"ut."utSline,A di#isor is e'ual to zero A E
endE
@
User Def&ned E,ce$t&n:-
Declaration --
Syn:-
OeCce"tion name- 0Cce"tionE
0C:
in#alidchoice eCce"ionE
Raising %f $n 1ser Defined 0Cce"tion --
Syn:-
2f cond then raise Ouser defined eCce"tion-E
end ifE
0C:-
K Write a .l@S'l bloc3 to create a user defined eCce"tion called in#alid choice and raise the same if the
choice is other than one and two. 2f the choice is one "rint mathematical table or 2f choice is two "rint the
factorial #alue or other than to raise the user defined eCce"tion.
declare
n numberE
ch numberE
f number :I 1E
in#alidch eCce"tionE
begin
n :I &noE
ch :I &choiceE
if ch in ,1( ) then
if ch I 1 then
for i in 1...1>
loo"
dbmsSout"ut."utSline,n QQ A K A QQ i QQ A I A QQ n K i E
end loo"E
elseif ch I ) then
for i in 1...n
loo"
f :I f K iE
end loo"E
dbmsSout"ut."utSline,A factorial #alue is A QQ f E
end ifE
else
raise in#alidchE
end ifE
eCce"tion
when in#alidch then
dbmsSout"ut."utSline,A wrong choice A E
endE
@
Cursrs
2t is an identifier gi#en to the memory location.
!y"es :-
1 2m"licit cursor ) 0C"licit cursor
1 2m"licit cursor --
!hese are declared by .5 @ S45 and can "rocess only one row at a time.
) 0C"licit cursor --
!hese are declared by the user li3e normal #ariables in the declaration section of the bloc3 using cursor
statement which can "rocess more than one row and the rows that are "rocessed by eC"licit cursors are
reffered to as acti#e set.
+'$l&c&t Cursr Attr&*utes --
1 S45 U row count --
Counts the no.of rows that are "rocessed by the .5 @ S45 statements.
declare
n numberE
begin
delete from em" where n I &em"noE
n:Is'l UrowcountE
dbmsSout"ut."utSline,Ano.of rows deleted are A QQ nE
endE
@
) S45 Ufound--
Returns true if the row is "rocessed otherwise flase.
declare
erec em"Urowty"eE
begin
select K into erec from em" where em"noI&noE
if s'lUfound then
dbmsSout"ut."utSline,A Records are found A E
dbmsSout"ut."utSline,A0m"no A QQ erec(em"noE
---
---
else
dbmsSout"ut."utSline,ARecord are not found A E
end ifE
endE
@
/ S45 Unotfound --
Returns true if the row is not "rocessed( otherwise true.
declare
erec em"Urowty"eE
begin
select K into erec from em" where em"noI&noE
if s'lUnotfound then
dbmsSout"ut."utSline,ARecord are not found A E
else
dbmsSout"ut."utSline,A Records are found A E
dbmsSout"ut."utSline,A0m"no A QQ erec(em"noE
---
---
end ifE
endE
@
E,$l&c&t Cursr Attr&*utes :-
!here are controlled by the following &our $ctions.
1 declaration of cursor using cursor statement in the declaration section of the bloc3.
Syn :-
cursor Ocursor identifier- L,argument listM is
'uery eC"rE
cursor identifier -- is name of the cursor.
'uery eC"r. -- is any 'uery statement.
0C:
declare
cursor c is select K from em"E
) %"ening of Cursor 1sing %"en Statement --
When e#er the cursor is o"ened cursor is always "ointed to the first rows in the acti#e set.
Syn:
o"en Ocursor identifier- L,argument listME
0C:
declare
cursor c is select K from em"E
begin
o"en cE
/ &etch statement --
&etch statement "o"ulates the current row data into the corres"onding #ariables or record ty"e
#ariable . 0ach fetch
statement causes the cursor to mo#e itAs "ointer to the neCt row in the acti#e set.
Syn:
fetch Ocursor identifier- into #ar1( #ar)( ........... E
%R
fetch Ocursor identifier- into Orecord- E
0C:
declare
cursor c is select K from em"E
erec em"Urowty"eE
begin
o"en cE
fetch c into erecE
endE
@
6 Close --
2t is used to close the cursor that is o"ened.
0C:
declare
cursor c is select K from em"E
erec em"Urowty"eE
begin
o"en cE
loo"
fetch c into erecE
dbmsSout"ut."utSline,A 0m":o A QQ erec.em"noE
dbmsSout"ut."utSline,A 0m":ame A QQ erec.enameE
---
---
end loo"E
close cE
endE
@
.l/ Of Cntrl :-
Sim"le 2f --
if cond then
stat,sE
end ifE
2f - 0lse --
if cond then
stat,sE
else
stat,sE
end ifE
0lse 2f 5adder --
if cond then
stat,sE
else
if cond then
stat,sE
else
if cond then
stat,sE
else
stat,sE
end ifE
end ifE
end ifE
+ulti"le 2f --
if cond then
statE
elsif cond then
statE
else
statE
end ifE
E, :-
Sim"le 2f
declare
age number :I &ageE
begin
if age -I 1D then
dbmsSout"ut."utSline,A eligible AE
end ifE
endE
@
2f 0lse
declare
age number :I &ageE
begin
if age -I 1D then
dbmsSout"ut."utSline,A eligible AE
else
dbmsSout"ut."utSline,A not eligible AE
end ifE
endE
@
0lse 2f 5adder
declare
name #archar),1> :I AsanthoshA E
m number,) :I&mathsE
c number,) :I &cheE
" number,) :I&"hyE
tot numberE
a numberE
res #archar),1>E
di# #archar),1>E
begin
tot :I mF"FcE
a :I tot @ /E
if m-I6> and c-I6> and "-I6> then
res :IA"assAE
else
res :IAfailAE
end ifE
if res I A"assA and a -I=8 then
di# :IAfirstAE
else
if resIA"assA and a-IB> then
di# :IAsecondAE
else
if resIA"assA and aOB> then
di# :IAthirdAE
else
di# :IAKKKK A E
end ifE
end ifE
end ifE
dbmsSout"ut."utSline,Aname is A QQ nameE
dbmsSout"ut."utSline,Amaths is A QQ mE
---
---
---
endE
@
Com"leC 2f Construct
2nstead of writing else if different in this we ha#e to write elsif instead of writing else if.
declare
name #archar),1> :I AsanthoshA E
m number,) :I&mathsE
c number,) :I &cheE
" number,) :I&"hyE
tot numberE
a numberE
res #archar),1>E
di# #archar),1>E
begin
tot :I mF"FcE
a :I tot @ /E
if m-I6> and c-I6> and "-I6> then
res :IA"assAE
else
res :IAfailAE
end ifE
if res I A"assA and a -I=8 then
di# :IAfirstAE
elsif resIA"assA and a-IB> then
di# :IAsecondAE
elsif resIA"assA and aOB> then
di# :IAthirdAE
else
di# :IAKKKK A E
end ifE
dbmsSout"ut."utSline,Aname is A QQ nameE
dbmsSout"ut."utSline,Amaths is A QQ mE
---
---
---
endE
@
5oo"ing Constructors %R 2terati#e Statements :-
Re"etation of statements as long as condition is true and eCit. When condition is false.
De"ending u"on the Control Structure 5oo"ing Constructs are mainly of ) !y"es( they are :-
1 0ntry Control 5oo" ) 0Cit Control 5oo"
1 0ntry Control 5oo" --
0nters into the loo" and eCecutes the body of the loo" only when condition is true.
) 0Cit Control 5oo" --
0nters the 5oo" and 0Cecutes the body of 5oo" atleast once 1nconditionally and then Chec3s for the
Condition.
.oints !o Remember :-
1 2nitialisation of a #alue to a #ariable.
) Condition chec3ing.
/ 0Cecution of body of the 5oo".
6 Ste" #alue , incrementation %r decrementation .
1 5oo" :- ,infinite loo"
loo"
statementsE
end loo"E
0C:- .rogram to "rint natural noAs.
declare
i number :I 1E
begin
loo"
dbmsSout"ut."utSline, i E
i :I iF1E
end loo"E
endE , "ress Ctrl F *rea3 -- !o Sto"
@
0Cit Statements :-
2t is used to terminate the 5oo".
Syn :-
loo"
stat,sE
eCit when condE
end loo"E
0C:- .rogram to "rint noAs from 1 to 1>>
declare
i number :I 1E
begin
loo"
dbmsSout"ut."utSline, i E
i :I iF1E
eCit when i I 1>1E
end loo"E
endE
@
While 5oo" :-
-- 0ntry Control 5oo".
Syn:-
while cond
loo"
stat,sE
end loo"E
0C:-
declare
i number :I 1E
begin
while iOI1>>
loo"
dbmsSout"ut."utSline, i E
i :I iF1E
end loo"E
endE
@
&or 5oo" :-
Syn :-
for #ariable in Lre#erseM low #alue ... high #alue
loo"
stat,sE
end loo"E
0C:-
declare
i number :I 1E
begin
for i in 1...1>>
loo"
dbmsSout"ut."utSline, i E
end loo"E
endE
@
0C:- !o "rint the re#erse #alues.
declare
i number :I 1E
begin
for i in re#erse 1...1>>
loo"
dbmsSout"ut."utSline, i E
end loo"E
endE
@
*ranching Statements :-
7oto --
2t is a *ranching or 1nconditional Statement to transfer the control from one "art of the "rogram to other
1nconditionally by S3i""ing the Statement *etween.
Syn:-
5abel Defination
goto labelnameE OO label name --
---
---
0C:- OO a --
declare
C number :I 1E
begin
OOa--
dbmsSout"ut."utSline,CE
C :I CF1E
if C O 1> then
goto aE
end ifE
endE
@
Cursrs
0C"licit Cursors :-
declare
cursor c is select K from em"E
erec em"Urowty"eE
begin
o"en cE
loo"
fetch c into erecE
dbmsSout"ut."utSline,A 0m" :o A QQ erec.em"noE
dbmsSout"ut."utSline,A 0m" :ame A QQ erec.enameE
---
---
end loo"E
close cE
endE
@
1 !he 5oo" Statement is not gi#en only the first record contains are &etched from the acti#e set.
) !he 5oo" Statement is gi#en it &etch the record to set the acti#e as long as condition is true comes out
the 5oo"( when the no record is found try to fetch the contains
of that record gi#ing an error fetch is out of se'uence.
0C"licit Cursor $ttributes :-
1 Cursor identify U notfound --
Returns true if the &etch Statement is not a#ailable to fetch the record contains from the acti#e
statement( otherwise false.
0C:-
declare
cursor c is select K from em"E
erec em"Urowty"eE
begin
o"en cE
loo"
fetch c into erecE
if cUnotfound then eCitE
end ifE
dbmsSout"ut."utSline,A 0m" 0name A QQ erec.enameE
---
---
end loo"E
close cE
endE
@
) Cursor 2dentify Ufound --
0C:-
declare
cursor c is select K from em"E
erec em"Urowty"eE
begin
o"en cE
loo"
fetch c into erecE
if cUfound then eCitE
dbmsSout"ut."utSline,A 0m" 0name A QQ erec.enameE
---
---
end ifE
end loo"E
close cE
endE
@
/ Cursor 2dentify Urowcount --
Counts the no.of rows that ha#e been fetch so far from acti#e set.
0C:-
declare
cursor c is select K from em"E
erec em"Urowty"eE
n numberE
begin
o"en cE
loo"
fetch c into erecE
n :I cUrowcountE
if n-8 then eCitE
dbmsSout"ut."utSline,A 0m" :ame A QQ erec.enameE
---
---
end ifE
end loo"E
close cE
endE
@
6 Cursor 2dentifier Uiso"en --
Returns true if the cursor is o"ened( otherwise false.
0C:-
declare
cursor c is select K from em"E
erec em"Urowty"eE
begin
if cUiso"en then
fetch c into erecE
else
o"en cE
fetch c into erecE
end ifE
dbmsSout"ut."utSline,A 0m" :ame A QQ erec.enameE
---
---
close cE
endE
@
Cursor With &or 5oo" --
$ cursor &or 5oo" im"licitly declare itAs loo" in the order of record at Urowty"e( o"en the cursor and
re"etidly fetches the rows of #alues from the acti#e set into fields in the record.
Syn:-
for indeCrecord in cursorname
loo"
stat,sE
end loo"E
0C:-
declare
erec em"Urowty"eE
cursor c is select K from em"E
begin
for erec in c
loo"
dbmsSout"ut."utSline,A 0m" :ame A QQ erec.enameE
---
---
end loo"E
endE
@
Cursor With .arameters --
.arameters allows the #alues to be "ause a cursor when it is o"en and used eCecutes with in the 'uery.
Which means that the eC"ress cursor is o"ened.
Syn:-
cursor identifier ,"arametername dataty"e( "arametername dataty"e( ---- is 'uery eC"rE
when the cursor is ladder o"en #alues are "assed to each of the "arameters "ositionally.
Syn:-
o"en cursor ,argumnts listE
:ote :-
!he #alues that are said or noon actual arguments and the #alues that are recei#ed.
0C:-
declare
cursor c ,no number( name #archar) is select K from em"
where em"noIno and enameInameE
erec em"Urowty"eE
begin
o"en c,=</6(ASC%!!AE %R o"en c,&no(A&nameAE
loo"
fetch c into erecE
if cUnotfound then
eCitE
end ifE
dbmsSout"ut."utSline,A 0m" :o A QQ erec.em"noE
dbmsSout"ut."utSline,A 0m" :ame A QQ erec.enameE
---
---
end loo"E
close cE
endE
@
0ntering !he ;alues $t Run!ime --
0C:-
declare
cursor c ,no number( name #archar) is select K from em"
where em"noIno and enameInameE
erec em"Urowty"eE
a numberE
b #archar),1>E
begin
a :I&noE
b :IA&nameAE
o"en c,a(bE
loo"
fetch c into erecE
if cUnotfound then
eCitE
end ifE
dbmsSout"ut."utSline,A 0m" :o A QQ erec.em"noE
dbmsSout"ut."utSline,A 0m" :ame A QQ erec.enameE
---
---
end loo"E
close cE
endE
@
Su* Prgra's
di#iding a "rogram into "iceses.
1 Calling @ +ain .rogram ) Called @ Sub .rogram
!wo ty"es of Sub.rograms.
1 .rocedures -- will not return a #alue.
) &unctions -- return a #alue.
$d#antages --
1 a#oiding the re"etition of code.
) read ability.
.rocedures --
Syn:-
create L %r re"laceM "rocedure O"rocedure name- L,arguments listM
"rocedure bodyE
---
---
end L"rocedure nameME
0Ccution %f a .rocedure --
Syn:-
0Ccute O"rocedurename- L,argument listME
.rocedure With%ut .arameters
0C:- !o "rint the factorial #alue.
1 Creation of .rocedure
S45- ed f
create or re"lace "rocedure fact is
n number :I &noE
f number :I 1E
begin
for i in 1...n
loo"
f :I f K iE
end loo"E
dbmsSout"ut."utSline,A factorial is A QQ fE
endE
@
) Sa#e & 0Cit , $lt F &6
/ RfE
.rocedure created
0Ccution
S45 - 0Ccute factE
.rocedure With .arameters --
.arameters in the #alues "assed the arguments from the command line when the "rogram is eCecuted.

0C:- !o "rint the factorial #alue.
1 Creation of .rocedure
S45- ed f
create or re"lace "rocedure fact,n number is
f number :I 1E
begin
for i in 1...n
loo"
f :I f K iE
end loo"E
dbmsSout"ut."utSline,A factorial is A QQ fE
endE
@
) Sa#e & 0Cit , $lt F &6
/ RfE
.rocedure created
0Ccution
S45 - 0Ccute fact,&noE
0C:- Create a "rocedure to acce"t a string and "rints itAs re#erse.
create or re"lace "rocedure re#str,str #archar) is
l numberE
" #archar),1>E
begin
l :I length,strE
for i in re#erse 1...l
loo"
" :I " QQ substr,str(i(1E
end loo"E
dbmsSout"ut."utSline,A Re#erse string A QQ "E
endE
@
0Ccution --
S45 - 0Ccute re#str, A&stringA E
0C:- Whether the string is "olindrom or not
create or re"lace "rocedure "olin,str #archar) is
l numberE
" #archar),1>E
begin
l :I length,strE
for i in re#erse 1...l
loo"
" :I " QQ substr,str(i(1E
end loo"E
dbmsSout"ut."utSline,A +ain string A QQ strE
dbmsSout"ut."utSline,A Re#erse string A QQ "E
if str I " then
dbmsSout"ut."utSline,A "olindrom A E
else
dbmsSout"ut."utSline,A :ot "olin A E
end ifE
endE
@
0Ccution --
S45 - 0Cecute "olin, A&stringA E
.unct&ns :-
Syn :-
create Lor re"laceM function Ofunctionname- L,argumentslistM return Odataty"e- is @ as
declaration of #ariables
---
---
begin
0Ccutable statementsE
---
---
return ,#ar @ eC"rE
end Lend functionME
0Cecution
Syn:-
declare
local #ariablesE
---
---
begin
#ar I functionnameL,arguments listME
---
---
endE
&unction With%ut $rguments
0C:
S45 - ed sim"le
create or re"lace function si return number is
" number :I &amtE
t number :I &timeE
r number :I &rateE
s numberE
begin
s :I ," K t K r @ 1>>E
return ,sE
endE
@
S45 - Rsim"le
&unction created
0Ccution
S45- ed sim"le1
declare
C numberE
begin
C :I siE
dbmsSout"ut."utSline, A intrest is A QQ CE
endE
@
S45 - Rsim"le1
.unct&n /&t( Argu'ents --
0C:-
S45 - ed sim"le
create or re"lace function si," number( t number( r number return number is
s numberE
begin
s :I ," K t K r @ 1>>E
return ,sE
endE
@
S45 - Rsim"le
&unction created
0Ccution
S45- ed sim"le1
declare
C numberE
begin
C :I si,&""( &tt( &rrE
dbmsSout"ut."utSline, A intrest is A QQ CE
endE
@
S45 - Rsim"le1
Pac!ages
!he collection of .rocedure and &unctions.
1 .ac3age S"ecification --
declaration of %b?ects , .rocedure @ &unction ( .rocedure and &unction .
Syn:-
create or re"lace "ac3age O"ac3age name- is @ as
declaration of ob?ectsE
---
---
end L"ac3age nameME
) .ac3age *ody
contains descri"tion @ ob?ects definition.
Syn:-
create or re"lace "ac3age body O"ac3age name- is @ as
definition of ob?ectsE
---
---
endE
0Ccution of .rocedure from a .ac3age 0Ccution of .rocedure from a
.ac3age
Syn:-
0Cecute "ac3agename."rocedure L,arguments listME 5ocal ;ar I
"ac3agename.functionL,arguments.listM
0C:-
Creation of a .ac3age containing a .rocedure with an $rgument.
S45 - ed "ac31
create or re"lace "ac3age "ac3 is
"rocedure e#od,n numberE
end "ac3E
@
S45 - ed body1
create or re"lace "ac3age body "ac3 is
"rocedure e#od,n number as
begin
if mod,n( )I> then
dbmsSout"ut."utSline, A 0#en A E
else
dbmsSout"ut."utSline, A %dd A E
end ifE
end e#odE
endE
@
S45 - 0Cecute "ac3.e#od,&noE %R 0Cecute "ac3.e#od,6E
0C:-
Creation of a .ac3age containing a &unction without an $rgument.
S45 - ed C
create or re"lace "ac3age "ac3 is
function re#no return numberE
end "ac3E
S45 - ed CC
create or re"lace "ac3age body "ac3 is
function re#no return number is
rem numberE
n number :I &noE
re# number :I >E
begin
while,n PI >
loo"
rem :I mod,n(1>E
re# :I re# K 1> F remE
n :I floor ,n @ 1>E
end loo"E
return re#E
end re#noE
endE
@
0Ccution
S45 - ed CCC
declare
C numberE
begin
C :I "ac3.re#no,E
dbmsSout"ut."utSline,A Re#erse A QQ CE
endE
@
0C:-
Creation of a .ac3age containing a &unction with an $rgument.
S45 - ed C
create or re"lace "ac3age "ac3 is
function re#no,n number return numberE
end "ac3E
S45 - ed CC
create or re"lace "ac3age body "ac3 is
function re#no,n number return number is
rem numberE
a numberE
re# number :I >E
begin
a :I nE
while,a PI >
loo"
rem :I mod,a( 1>E
re# :I re# K 1> F remE
a :I floor ,a @ 1>E
end loo"E
return re#E
end re#noE
endE
@
0Ccution
S45 - ed CCC
declare
C numberE
begin
C :I "ac3.re#no,&nE
dbmsSout"ut."utSline,A Re#erse A QQ CE
endE
@
0C:-
Creation of a .ac3age containing a .rocedure & &unction with an $rgument.
S45 - ed C
create or re"lace "ac3age "rocfunc is
"rocedure "erfect,n numberE
function arm,n number return numberE
end "rocfuncE
S45 - R C
.ac3age created
Creation of .ac3age *ody
S45 - ed CC
create or re"lace "ac3age body "rocfunc is
"rocedure "erfect,n number is
i number :I 1E
s number :I >E
r numberE
begin
while,i O n
loo"
r :I mod,n( iE
if r I > then
s :I sFiE
end ifE
i :I iF1E
end loo"E
if nIs then
dbmsSout"ut."utSline,n QQ A is "erfect A E
else
dbmsSout"ut."utSline,n QQ A is not "erfect A E
end ifE
end "erfectE
function arm,n number return number is
rem numberE
aarm number :I>E
nn numberE
begin
nn :InE
while,nn PI>
loo"
rem :Imod,nn( 1>
aarm :I aarm F rem K rem K remE
nn :Ifloor,nn @ 1>E
end loo"E
if nIaarm then
return 1E
else
return >E
end ifE
end armE
endE
@
0Cecution %f .rocedure &rom a .ac3age
S45 - 0Cecute "rocfunc."erfect,&noE
0Cecution %f &unction &rom a .ac3age
S45 - ed eC
declare
" numberE
begin
" :I"rocfunc.arm,&noE
if " I 1 then
dbmsSout"ut."utSline,A armstrong A E
else
dbmsSout"ut."utSline,A not A E
end ifE
endE
@
Data*ase "r&ggers
is fiCed when e#er on e#ent occurs.
0#ent --
interaction between user and the ob?ect of writing on the board.
%b?ect --
anything eCisting in the word ha#ing some "ro"erties.
.ro"erties --
#isual attributes of the ob?ect.
!y"es of Database !riggers --
1 before @ after delete ) before @ after insert / before @ after u"date
Creation of !rigger
Syn:-
create Lor re"laceM trigger Otrigger name- before @ after delete@ insert@ u"date on Otable- L for each rowM
---
---
endE
0C:-
Creation of record after delete
S45- ed e
create or re"lace trigger deltrig after delete on em"
begin
dbmsSout"ut."utSline,A record is deleted A E
endE
@
S45 - R eE
!rigger created
S45 - delete from em" where de"tnoI1>E
&or 0ach Row --
2f this ao"tion is used the trigger is fired same no.of times de"ending u"on the no.of the rows "resent in
the table.
S45 - ed e
Creation of record after delete
create or re"lace trigger deltrig after delete on em" for each row
begin
dbmsSout"ut."utSline,A record is deleted A E
endE
@
Creation of record after 1"date
S45 - ed e
create or re"lace trigger u"dtrig after u"date on em" for each row
begin
dbmsSout"ut."utSline,A record is u"date A E
endE
@
S45 - R e
!rigger created
S45 - u"date em"
set ename I AsanthoshA
where em"noI1>>E
Creation of record after 2nsert
S45 - ed e
create or re"lace trigger instrig after insert on em"
begin
dbmsSout"ut."utSline,A record is inserted A E
endE
@
S45 - R e
!rigger created
S45 - insert into em" ,em"no(ename(de"tno #alues ,1>>(AsanthoshA(/>E
0C:- !o create a !rigger based on two tables.
0m"1
em"no number,6( ename #archar),1>( desig #archar),1>( sal number,1>( )( de"tno number,).
!em"1
eno number,6( name #archar),1>( ?ob #archar),1>( salary number,1>( )( dno number,)( "er char,6.
S45 - ed trigger
create or re"lace trigger iudtrg after insert or u"date or delete on em"1 for each row
declare
a number,6E
b #archar),1>E
c #archar),1>E
d number,1>( )E
e number,)E
f char,6E
begin
if 2:S0R!2:7 then
a :I :new.em"noE
b :I :new.enameE
c :I :new. desig:
d :I :new. salE
e :I :new. de"tnoE
f :I A 2 A E
insert into tem"1 #alues,a(b(c(d(e(fE
elsif D050!2:7 then
a :I :old.em"noE
b :I :old.enameE
c :I :old. desig:
d :I :old. salE
e :I :old. de"tnoE
f :I A D A E
insert into tem"1 #alues,a(b(c(d(e(fE
elsif 1.D$!2:7 then
a :I :new.em"noE
b :I :new.enameE
c :I :new. desig:
d :I :new. salE
e :I :new. de"tnoE
f :I A 1 A E
insert into tem"1 #alues,a(b(c(d(e(fE
end ifE
dbmsSout"ut."utSline,A 0m":o A QQ aE
dbmsSout"ut."utSline,A 0:ame A QQ bE
dbmsSout"ut."utSline,A Desig A QQ cE
dbmsSout"ut."utSline,A Salary A QQ dE
dbmsSout"ut."utSline,A De"t:o A QQ eE
dbmsSout"ut."utSline,A Status A QQ fE
endE
@
S45 - R !riggerE
!rigger created
S45 - insert into em"1 #alues ,1>>(AabcA(AmngA(/8>>()>E
S45 - insert into em"1 #alues ,)>>(ACyzA(Acl3A(/>>>(/>E
S45 - insert into em"1 #alues ,/>>(AabcA(Aty"A()8>>(1>E
S45 - u"date em"1 set sal I 6>>>
where sal I /8>>E
S45 - delete from em"1
where em"noI/>>E
S45 - select K from em"1E
0m":o 0name Desig Sal Det":o
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
1>> abc mng 6>>> )>
)>> Cyz cl3 />>> />
S45 - select K from tem"1E
0:o :ame Gob Salary D:o .er
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
1>> abc mng /8>> )> 2
)>> Cyz cl3 />>> /> 2
/>> abc cl3 />>> /> 2
1>> abc mng 6>>> )> 1
/>> abc cl3 />>> /> D
Devel$er 0111
-- is a front end tool.
-- %racle -- &orms
Re"orts
7ra"hics
*oo3
&ront0nd !ool -- is an a""lication de#elo"ment tool by which boo3 and database is accessed.
0C:- de#elo"er )>>>( #isual basic( foC"ro,"ower tools
*an3 0nd !ool -- is nothing but the acti#al database.
0C:- %racle( Sybase( .aradoC( $ccess( &oC"ro
Oracle .r's
is a a""lication de#elo"ment tool for building client-ser#er based a""lications.
%racle &orm Com"onents -- / ty"es.
1 %racle forms designer
) %racle forms generate
/ %racle forms runform
1 %racle &orms Designer --
2t is the a""lication de#elo"ment en#ironment( where the user can wor3 with / ty"es of modles li3e :
1 &orms ) +enus / 5ibraries
Which includes set of #isual tools( that allow to the user to create( set their "ro"erties and right the code for
an a""lication.
. fmb -- ,form module binary
) %racle &orms 7enerate --
2t is used to create a""lication files which com"iles all of itAs codes ob?ects and create a file with an
eCtension .fmC
,form module
eCecutable
&ile -- $dministration -- Com"ile ,%R 7enerate Ctrl F !
/ %racle &orms Run&orm --
2t is used to eCecute the finish a""lication.
&ile -- Run ,%R Ctrl F R
&orms
-- .fmb ,&orm +odule *inary
-- .fmt ,&orm +odule !eCt
-- .fmC ,&orm +odule 0Cecutable
%racle &orm +odules :-
1 &orms +odules ) +enu +odules / 5ibraries +odules
6 %b?ect 5ibraries 8 *uiltin .ac3ages B Database %b?ects.
1 &orms +odules --
Collection whole and %b?ects.
) +enu +odules --
Collection of menu ob?ects and menu command code.
/ 5ibraries +odules --
Collection of .5@S45 "rocedures functions and "ac3ages.
7etting Started With &orms
Start -- .rogram -- De#elo"er )>>> -- &orms *uilder.
F -- 0C"anel - -- Colla"sal
7etting Started With &orms &rom S45
1 S45- host @ J f8>des/)
C:T%rawin<8TbinTf 8>des/) . eCe
7etting Connected !o %racle
) &ile -- Connect
7etting started with &orms &rom S45 & Connecting !o %racle --
S45- host@J f 8>des/) J scott@tigerRorcl
f 68
Des&gn "ls
5ay%ut 0diter --
2t allows the user for creating and arranging the interface editors( bilor "late teCt items and 7ra"hics in a
&orm. !he 5ayout 0ditor we can wor3 in a single Can#as( you which is dis"layed in windows at run time.
2n#o3ing of 5ayout 0ditor --
1 2n the double clic3 on the ob?ects icon for the Can#as ;iew you want to 0dit. ,%R
) 2n the %b?ect :a#igater ,%: Clic3 5ayout 0diter from the .o"u" +enu which is %btained by Right
Clic3ing the +ouse.
Can#al -- !he $rea when the 2tems are .laced.
5ay%ut 0diter !ool*ar
1 5ay%ut !ools
) *oiler .late Drawing !ools
/ 2tem Drawing !ools
6 &ill @ 5ine Color .aletts.
!hese are used to Create and +ani"ulate 2tems and *oiler.late %b?ects.
.ro"erties Window --
2t is used to set the .ro"erties of the %b?ects Created in the &orm and the +enu +odules. Whene#er and
%b?ect is Created it will ha#e own .ro"erties set. .ro"erties Window can be used to set the re'uired
.ro"erties for an %b?ect.
2n#o3ing %f .ro"erties Window --
1 Select the %b?ect and Clic3 !ools -- .ro"erties ,%R
) Double Clic3 on the %b?ect in 5ay%ut 0diter.
+enu 0diter --
2t is used to create Customized +enus.
2n#o3ing %f +enu 0ditor --
1 2n the %: (
Double Clic3 on +enu +odules %b?ect 2con. ,%R
) Clic3 !ools -- +enu0diter.
.5 @ S45 0ditor --
2t is the 0diter where the code is enter and Com"ile Code %b?ects. Which includes !riggers( Sub-
.rograms( .ac3ages( +enu 2tems( etc.(.
2n#o3ing %f .5 @ S45 0ditor --
Clic3 !ools -- .5 @ S45 0diter.
$bout 2tems & *loc3s
2tems the inter face %b?ects the dis"lay the infermation to the user and allow them interact.
1 *utton --
$ Rectangle which the !eCt 5abel %R an 7ra"hic inside.
) Chart 2tem --
$ bordered Rectangle that can dis"lay Chart %R any other dis"lay 7enerate by %racle 7ra"hics.
/ Chec3 *oC --
$ !eCt 5abel the Dis"lay the Current #alue as either Chec3 %R 1nChec3 any no.of Chec3 *oCes are
selected.
+te's
6 Dis"lay 2tems --
$ Read only !eCt *oC whose #alue must be assigned .rogramatically. !hat is user cannot modify teCt it
contains.
8 !eCt 2tem --
2ts read and Write !eCt *oC( it allowing the user to modify the contains any.
B 2mage 2tem --
$ *order to Rectangle of any size that can dis"lay 2mages fetched from the database %R any file System.
= Radio 7rou" --
Contains set of radio buttons out of which one is always selected.
D 5ist 2tem --
$ list of items are dis"layed either as a .o"list or !list or ComboboC.
Blc!s :-
2t is a logicall container of items( which "ro#ides the mechanisam for grou"ing related items for storeing(
dis"laying and mani"leting the records. : no.of bloc3s can be defined in a form( and the items in a bloc3
can "laced on different Can#as used and different windows.
!y"es of *loc3s --
1 *ase *loc3 ) Control *loc3
1 *ase *loc3 --
*ase *loc3 is the bloc3( which is associated with the table or a #iew( and can contain. 2t contain Control
2tems.
!he *ase *loc3s are related with *ase !able.
) Control *loc3s --
2t is the bloc3 which is not associated with the !able or ;iew( and can contain only Control 2tems.
!he Control *loc3s are not Related with any !able.
Creation %f *ase*loc3 :-
1 0C"and &orms :ode.
) Choose *loc3s :ode from %b?ect :a#igator,%: & Double Clic3 on it. ,%R
Choose the ,F o"tion !ool from !oll *ar
Creating a *loc3 :- !wo ty"es.
1 Data *loc3 Wizard ) +anu#ally
*loc3s & 2tems
1 Choose *loc3s :odes from %: & Double clic3 on it.


!o Select @ Deselect the Columns --
Clic3 on Columns *utton from Dialog *oC.
double clic3 on the column to deselect

Changing of Column 9eadings --
Select the !eCt !ool from !ool*ar & !y"e the Re'uired Column 9eading.
Changing of 2tem !y"e ,Default is !eCt 2tem --
Choose the Re'uired 2tem!y"e from the 5ist. ,%R
Choose the Re'uired 2tem from %.:. @ 5.0.( Right clic3 the +ouse & Choose .ro"erties 2tem !y"e.


!o S"ecify the 5ay%ut of the &orm( Clic3 %n 5ay%ut *utton :-

is effected only in the !abular &orm
-- Select 2ntegrity Constraints chec3 boC to $""ly constraints a#aliable on the columns.
-- Scroll *ar Chec3*oC to dis"lay the for ;ertical Score*ar for easy :a#igation of reocrds.
Setting the .ro"erties of Scroll *ar --
&rom %b?ect :a#igator( Choose the *loc3 & Right Clic3 the +ouse & Choose .ro"erties.
Scroll*ar

Choose the *utton .alette Chec3 *oC to Dis"lay *utton .alatte with follwoing *utton .redefined.
Run .r' Menu O$t&ns
$ction --
Sa#e -- !o Sa#e the !ransaction.
0Cit -- !o 0Cit &rom the Run&orm.
.rint --
*loc3 :-
1. :eCt -- !o goto the :eCt *loc3.
). .re#ious -- !o goto the .re#ious *loc3.
Record +enu :-
1. :eCt -- !o goto the :eCt Record.
). .re#ious -- !o goto the .re#ious Record.
/. Scroll 1" -- !o Scroll1" by %ne Screen &ull of Records.
6. Scroll Down -- !o Scroll Down by %ne Screens &ull of Records.
8. Clear -- !o Clear the Containts of the Record.
B. Remo#e -- !o Delete the Current Record.
=. 2nsert -- !o 2nsert the Record at Current .osition.
D. Du"licate -- !o Du"licate the Record. ,%R Co"y the Record.
<. Clear -- !o Clear the Containts of the *loc3.
0dit +enu :-
1. Cut -- !o Cut the Select !eCt.
). Co"y -- !o Co"y the Select !eCt.
/. .aste -- !o .aste the !eCt.
6. 0dit -- 2n#o3e the Default 0ditor a#ailable( allowing the user to enter a :ew that +odify the 0Cisting.
&ield +enu :-
1. .re#ious -- !o goto the .re#ious &ield.
). :eCt -- !o goto the :eCt &ield.
/. Clear -- !o Clear the &ields.
6. Du"licate -- !o Du"licate the &ield.
4uery :-
1. 0nter -- !o 0nter the 4uery on which the records are one to the dis"layed.
). 0Cecute -- 0Cecutes the 4uery.
"r&ggers :-
2s &iCed when on 0#ent %ccurs.
0#ent -- 2nteraction between 1ser and %b?ect.
"#$es Of "r&ggers :- / ty"es.
1 &orm 5e#el !riggers ) *loc3 5e#el !riggers / 2tem 5e#el !riggers

2 +te' Level "r&ggers :-
When-*utton-.ressed
When *utton is .ressed( !rigger is 0Cecute.
.ush *utton
Control 2tem
Dis"lay 2tem
1 Create a *ase *loc3
) Clic3 on !ool !eCt & !y"e $nnsalary in 5ay%ut 0ditor.
/ Select Dis"lay 2tem from 5ay%ut 0ditor !ool*ar & .lace it on the Can#as ,*loc3.
Changing the .ro"erties of Dis"lay 2tem( Choose Dis"lay 2tem & Right Clic3 the +ouse & Choose
.ro"erties.
.ro"erties --
1 Dis"lay 2tem
:ame -- annsal
Database 2tem -- &alse
) Creation of .ush *utton --
Choose .ush *utton !ool from 5ay%ut 0ditor !ool*ar & .lace it on the Can#as ,*loc3.
.ro"erty
:ame --
5abel ,%R Ca"tion -- calc
Codeing %n .ush*utton
Choose the *utton & Right Clic3 & Choose .5 @ S45 0ditor.
:annsal : I :;5, :Comm(> F : sal K 1)E
) %(en Rad& C(anged
%ccurs whene#er the Radio *utton is Changed from the 7rou".
Creat&n Of Rad& Buttn --
When a Radio 7rou" is Created you associate a s"ecific Data #alue with each Radio *utton in the 7rou".
When the user selection the Radio *utton the #alue of Radio 7rou" Changes the #alue that is associated
is the select *utton.
$ Radio 7rou" can include any no. of Radio *uttons( which can be sized( "osition and &ormatted
2ndi"endently of each other
!he Radio *utton can be selected by Clic3ing with the +ouse %R by :a#igating the "ointer to the Radio
*utton to .ress the 0nter Ney.
Selecting a :ew Radio *utton Deselects the .re#ious Selected *utton( that is at Runtime only %ne Radio
*utton can be Selected at any !ime.
Creation %f Radio 7rou"s ,%R 2tem --
Choose Radio *utton !ool from the 5ay%ut 0ditor !ool*ar and .lace it on the can#as.
When creating the Second Radio *utton Choose :ew( to "lace the Radio *utton at :ew Radio 7rou".
Choose %N *utton to .lace the *utton in the Same 7rou".
.ro"erties of Radio *utton
5abel -- 1>U
;alue -- 1>
.ro"erties %f Radio 7rou"
Choose the Radio 7rou" of the %b?ect :a#igater and set itAs .ro"erties.
1 :ame --
) Default ;alue --
0C:-
Structure of Stud !able
Rno number,)( :ame #archar),1>( Course #archar),1>( !ot&ees number,8( Dis number,)(
Dis$mt number,6( &ee.aid number,6( &ee%fDis number,6( *al&ee number,6.
1 Create a *ase *loc3 ,stud
) Choose Dis 2tem from 5ay%ut 0ditor & set its .ro"erty
2tem!y"e -- Radio7rou"
Creation %f Radio *utton --
Choose Radio *utton !ool &rom 5ay%ut 0ditor !ool *ar & .lace it on the Can#as by Clic3ing on %N
*utton.
Re"eat the same( de"ending on the :o. of Radio *uttons in a 7rou".
.ro"erties %f Radio *uttons
Choose !he Radio *utton & set in .ro"erty from 5ay%ut 0ditor.
5abel -- )8U
;alue -- )8
Default ;alue
Code %n Radio 7rou" ,%b?ect :a#igator
Choose Radio7rou" from %b?ect :a#igator & Right Clic3 the +ouse & Choose .5 @ S45 0ditor.
%(en-Rad&-C(anged
if : dis I )8 then
: disamt : I : totfees K )8 @ 1>>E
elsif : dis I 8> then
: disamt : I : totfees K 8> @ 1>>E
else
: disamt : I>E
end ifE
: feeafdis : I : totfees - : disamtE
L&st +te's :-
5ist 2tem is a 5ist of a !eCt 0lements( that can be Dis"layed as 0ither a .o"5ist( !eCt5ist %R Combo*oC.
$ 5ist 2tem Dis"layes &iCed no.of 0lements u"to /> Characters 5ong. $t Runtime the 5ist 0lements can
be $dded %R Remo#ed.
i .o"5ist --
2t a""ears initialized as the single field( similar to the either of teCt field( when the user select the 5ist 2con
the 5ist of a#ailable choise a""ears.
ii !eCt 5ist --
2t a""ears the rectangle boC( which dis"lays fiCed no.of #alues. 2n the !eCt 5ist contains of the #alues(
that can not be dis"layed due to the discrible area of the item of the "articular Scroll *ar a""ears allowing
the user to #iew and select undis"layed #alues.
iii Combo *oC --
Combaines the futures of both 5ist and !eCt 2tems.
5ist 0lement ;alues --
When a Create a 5ist 2tem you must associated the data #alue with each element in the 5ist. When an
%"erator selects the 0lements the #alue of the 5ist 2tem Changes to the #alue associated with that
0lement.
!rigger
%(en-L&st-C(anged
1 Create a *ase *loc3 ,stud.
) Choose Course from 5ay%ut 0ditor & Set its .ro"erty .ro"erty
Select +ore
%"tion
a 2tem !y"e - 5ist 2tem
b 5ist 0lements - !hese are ) ty"es i 5ist 0lement ii 5ist ;alue
c 5ist Style - .o"5ist ,Default
!5ist
Combo*oC
K Code %n Course
When-5ist-Changed
if : course I AdcaA then
: totfee : I 6>>>E
elsif : course I A"gdcaA then
: totfee : I B>>>E
else
: totfee : I 1>>>>E
end if E
--
!o change the 2tem !y"e in !eCt !o Dis"lay( select the "ro"erty window and change the item ty"e.
%(en-)al&date-+te'
is fired when an 2tem is ;alidated.
-- ;alidation +eans !o Chec3 the Data 0ntered is ;alid @ :ot.
0C:-
Rno ,When-;alidate-2tem
if : Rno I > %R : Rno is null then
message, ARoll :o should not be 5eft *lan3A E
Raise &orm-!rigger-&ailureE
0nd if E
Pre-"e,t-+te'
%ccurs when the !eCt 2tem 7ot &ocus.
0C:-
!ot,.re-!eCt-2tem
: !ot: I: s1 F : s) F : s/ E
Pst-"e,t-+te'
%ccurs when the !eCt 2tem 5ost &ocus.
0C:-
!ot,.ost-!eCt-2tem
: $#g : I : !ot @ / E
Muse Events :-
1 %(en-Muse-Leave
%ccurs when in the +ouse .ointer is away from the %b?ect.
0C:-
S/,When-+ouse-5ea#e
: tot : I : s1 F : s) F : s/ E
) %(en-Muse-Enter
%ccurs when in the +ouse is .ointing to an %b?ect.
0C:-
!ot,When-+ouse-0nter
: tot : I : s1 F : s) F : s/ E
/ %(en-Muse-Cl&c!
%ccurs when in the +ouse *utton is Clic3 an %b?ect.
0C:-
!ot,When-+ouse-Clic3
: tot : I : s1 F : s) F : s/ E
6 %(en-Muse-Du*leCl&c!
%ccurs when in the +ouse *utton is DoubleClic3 an %b?ect.
0C:-
!ot,When-+ouse-DoubleClic3
: tot : I : s1 F : s) F : s/ E
8 %(en-Muse-D/n
%ccurs when in the +ouse *utton is .ressed Down an %b?ect.
0C:-
!ot,When-+ouse-Down
: tot : I : s1 F : s) F : s/ E
B %(en-Muse-U$
%ccurs when in the +ouse *utton is .ressed 1" an %b?ect.
0C:-
!ot,When-+ouse-1"
: tot : I : s1 F : s) F : s/ E


= %(en-Muse-Mve
%ccurs when in the +ouse *utton is +o#e an %b?ect.
0C:-
!ot,When-+ouse-+o#e
: tot : I : s1 F : s) F : s/ E

Allerts :-
$n $llert is a +odule Window( the Dis"lay the +essage :otefying the %"erator at some $""lication
Condition.
$llert Style --
!he $llert Style denotes the Different 5e#el of +essages re"resent by 1ni'ue 2con( that Dis"lay the $lert
Windows.
%racle &orms has many *uitin $lerts( that Dis"lays .redefined +essages. 1ser can also Create his %wn
$lert( that Dis"layes in Res"onse to $""lication S"ecific 0#ents.
When an 0#ents %ccurs that causes an $lert to Dis"lay the %"erator must res"ond to $lert +essage by
Res"ond as Selecting a .redefined.
Creation %f $lert --
1 Create a *loc3 ,0m"
) Select the $lert :ode from %b?ect :a#igator and Double Clic3 on it. ,%R
Choose L F M Create *utton &rom %b?ect :a#igator !ool *ar.
Setting !he .ro"erties %f %n $lert --
1 Choose $lert from %b?ect :a#igator and set its .ro"erties( by Right Clic3ing the +ouse.
:ame -- a
$lert Style -- Sto" @ Caution @ :ote
*utton) -- Cancel
*utton1 -- %N
Default *utton -- *utton
+essage -- 0name Should :ot be 5eft *lan3.
$ttaching !he $lert !o !he 2tem --
Show- $lert -- ,*uilt-in
Return a numeric Constraint cors"onding to the *utton the %"erator select from the $lert ShowS$lert(
*uiltin "rocessor dis"layes the gi#en $lert and Returns the :umeric ;alue in %"erator Selects %ne of
!hree $lert *uttons.
Syn:-
ShowS$lert,$lert :ameE
0C:-
K Dis"lay an $lert when the #alue of 0m"loyee :ame is 5eft *lan3.
%(en-)al&date-+te' ,0name
declare
n numberE
begin
if : 0name is null then
message, A :ame should not be 5eft *lan3A E
n : I showSalert,AaAE
Raise &ormS!riggerS&ailure E
end if E
end E
Set-$lert-.ro"erty --
Changes the +essage !eCt for an eCisting $lert.
Syn:-
SetS$lertS.ro"erty , $lert :ame( .ro"erty( +essage E
$lert :ame -- name of the alert s"ecified.
.ro"erty -- s"ecifies the alert "ro"erty 5i3e :
a $lertS+essageS!eCt -- S"ecifies the teCt for the alert message.
b !itle -- S"ecifies the !itle of the $lert.
c +essage -- S"ecifies the message that is to re"lace the eCisting message %R currect
message.
0C:-
When-;alidate-2tem ,0name
declare
n numberE
begin
2f : 0name is null then
setSalertS"ro"erty, A a A( alertSmessageSteCt( A 0name should not be left blan3 A E
n : I showSalert, A aA E
Raise &ormS!riggerS&ailure E
0nd if E
0nd E
Ed&trs
0ditors is a "rogram that allows the user to enter a new teCt %R modify the eCisting teCt( which allows /
ty"es.
$ Default 0ditor --
2t "ro#ides standard editing feature including search and re"lace( co"y( cut and "aste.
2t is built into e#ery form and is automatically a#ailable for e#ery teCt item.
* System 0ditor --
2f this editor is a#ailable you can s"ecify oracle form to use this editor( rather than the default editor.
C 1ser :amed 0ditor --
2t is the editor create by the user( which as same teCt editing functionality as default editor( but it is named
ob?ect editor $ttributes such as window dis"lay Size( .osition and !itle can be s"ecify and it can be
dis"layed "rogrametically using the builtin .rocedure( A ShowS0ditorA inde"endently of any !eCt 2tem.
:ote:-
*y default user can in#o3e an 0ditor by :a#igating !eCt 2tem by choosing 0dit from 0dit +enu.
$nd 0ditor can also be dis"layed "rogrametically by eCecuting A 0ditS!eCtS2tem A built in .rocedure( when
the !eCt 2tem.
S(/2Ed&tr --
Dis"lays the gi#en editor at the gi#en co-ordinates and "asses the string editor %R rettri#es the eCisting
string from the 0ditor. 2f no co-ordinates su""ly the editor is dis"lay at the default "osition s"ecified in the
design time.
Syn:-
showSeditor ,editor name( message in( C( y( message out( result E
.ro"erties %f $n 0ditor --
1 Creation --
Double clic3 on the 0ditors :odes from the %b?ect :a#igater.
) .ro"erties --
:ame -- a
W .osition -- 1>
H .osition -- )>
9eight -- 1D>
Width --
!itle --
*ottom !itle --
/ $ttaching user defined 0ditor to the re'uire item.
6 Choose the Re'uire 2tem from the 2tems :ode of the %b?ect :a#igator and set itAs .ro"erties.
a 0ditor -- Choose user defined editor from the list.
0C:-
.reS!eCtS2tem ,0name
declare
res booleanE
begin
showSeditor , A aA( : 0name( 1>(18( : 0name( Res E
0nd E
5ist of ;alues ,5%;S --
2t is scrollable "o"u" window that "ro#ides the o"ertor with editor a single %R multi column selecting 5ist.
$t runtime oracle forms dis"layes the Olist- on the status line when e#en low.
%neAs in#o3e either "rogrmmatically %R by user re'uest lo# a""ears in a madul window allowing the
o"erator to selectSsingle #alue.
5%; Return 2tems --
While creating an 5%; s"ecify( which columns from the underline record grou" should be included in the
5%;.
2t can set the return item for any column that is included in the 5%;.
2n the %"erators select the Choice from the 5%; %racle &orms assigns the #alues to the Columns in the
selected Record to their Corres"onding Return 2tems.
I Creation %f 5%;s --
1 &rom 0Cisting Record 7rou"
) !able.Column
Choose 5%;As :ode from %b?ect :a#igator & Double Clic3 on it & Choose it.
1 Creation of Record 7rou" --
Choose Record 7rou" from %b?ect :a#igator & Double Clic3 on it & Write the 'uery as follow .
0C:-
select distinct ?ob from em" order by ?ob E
) !able .Column --
0C:-
em".?ob E
/ 0C:-
select distinct ?ob from em" order by ?ob E
22 $ttaching of 5o# to Re'uired Column --
Select the Re'uired Column ,?ob from the 2tems :ode of %b?ect :a#igator & set itAs .ro"erty .
5%; -- ,:ame of 5%; Created
default I :155
222 .ro"erties %f 5%; --
Choose 5%; Created from %b?ect :a#igator ,%: & set its .ro"erties .
:ame --
Column +a""ing --
Return 2tem -- :ame of the column where the selected #alue from the 5%; is to be returned.
$uto Dis"lay -- &alse @ !rue
2t is default &alse( .ress &< to 7et the 5ist.
$uto S3i" -- &alse @ !rue
2t is default &alse( 1ser 5%;As to .ress !$* to :a#igate to :eCt Column.
:ote :-
2f 5%;As is Creating 1sing Record 7rou" the .ro"erties need not to be set.
.ress &< to get the list and Ctrl F !ab to get the :eCt #alue the 5ist( and .ress Ctrl F 4 to Sto".
)&sual Attr&*utes :-
!hese are the &ont( Colour and .attern .ro"erties ( that are set for the &orm and +enu %b?ects( which
includes the &ont .ro"erties ( 5i3e &ont:ame( &ontStyle( &ontSize & &ontWidth.
) Colour and .anel .ro"erties &oure7round and *ac37roud( Colour & &ill.
Creation of ;issual $ttributes --
1 !he .ro"erties Window set the ;issual $ttribute :ame .ro"erties and Set the ;issual $ttributes 5i3e
&ont:ame( &oure7round( Colour & etc.(.
,%R
) !he 5ayout 0ditor Select the 2tem in the Can#as and Choose the Designed &ont( Colour( $ttributes from
the &ont( &illColour( !eCtColour .allets.
,%R
/ Designed a :amed ;isual $ttribute %b?ect in the $""ro"riate &ont( Colour( .attern Settings and $""ly it
to %ne %R +ore %b?ects with the same +odule.
,%R
6 Creating a .ro"erty Class that includes ;isual $ttributes .ro"erties and then base %b?ects on it that
2nherit those .ro"erty
Creation %f ;isual $ttribute 7rou" --
Choose ;isual $ttribute from %b?ect :a#igator ,%: & Double Clic3 on it.
.ro"erties --
:ame --
&ont:ame --
&ontSize --
&ontStyle --
&ontWidth --
&ontWeight --
--
$ttaching the ;isual $ttribute 7rou" to the Re'uired Column( Choose the Re'uired Column from 2tems
:ode of !he %b?ect :a#igator ,%: & Set its .ro"erties .
1 ;isual $ttribute :ame -
Choose !he :ame .ro"erty 2n $ttribute.
%&nd/s
$ &orm can ha#e any :o.%f Windows e#ery &orm $utomatically includes a default window named
window.
$dditional windows can be created by inserting %b?ect :a#igator in the windows.
&or each window that is created create at 5east %ne Con#as ;iew. !hat $ssociate the Can#as #iew with
the Window by setting the Can#as ;iew .ro"erties .
+D2 ,+ulti"ule Documents 2nterface --
+D2 $""lications dis"layes the default .arent Window called the $""lication %R +ain Window( and all are
the Windows in the $""lication( on item Documents are Dialog Windows.
!he +D2 $""lication Window is Created by the Windows +anager at Run !ime and does not $""ear in the
&orms 5ist of Windows. *ut %racle &orms allows the user to Re-Size( +inimize( +aCimize the +D2
$""lication Window .rogramatically using XSet-Window-.ro"ertyX.
%neAs Window is Created 2t can S"ecify the Window Style( that is Dialog %R Document by Setting the
Window .ro"erty .
C(&ld %&nd/ :-
1 Document Window --
Document Windows are always dis"layed within the +D2 $""lication Window &rame. 2f the user Re-Sizes
the $""lication Window( so that it is smaller than the Document Window( the Document Window is Cli""ed.
1ser can +aCimized the Document Window( so that it %ccu"ied the entire area of the $""lication Window.
Dialog Windows --
Dialog Windows are &ree &loating( and the 1ser can mo#e them %utSide of the $""lication Window( if
their as defined as mo#eable.
Set Window .ro"erty --
Sets the .ro"erty for the indicator window.
Syn:-
SetSWindowS.ro"erty,Windowname( .ro"erty( W( H
.ro"erty --
9eight --
!itle --
WindowSsize --
WindowSState -- :ormal( +inimize( +aCimize
Width --
&orm 5e#el !riggers :-
WhenS:ewS&ormS2nstance
0C:-
SetSWindowS.ro"erty,&ormsS+diSWindow( WindowSState( +aCimize E
SetSWindowS.ro"erty, &ormsS+diSWindow( !itle( A +y %wn $""lication Window A E
SetSWindowS.ro"erty, A Window > A( .osition( 8(1> E
SetSWindowS.ro"erty, A Window > A( !itle( AChile Window A E
Canvas
is an area where the %b?ects & *oiler .late !eCt 2tems are .laced.
When Windows ae defined for $""lications user can wor3 with !wo !y"es of %racle &orm %b?ects( that is
Can#asS;iews.
$ single &orm ha#e n no. of Windows Can#asS;iews on the *ac37round %b?ects on which 2nterface
2tems and the *oiler .lates %b?ects are .laced.
0ach Can#as ;iew dis"layed in Window.
!he Window %b?ect itself is frame "ro#ided by !itle *ar ma3ing with "ossible for the 1sers to Scroll mo#e
and Re-Size the Window. !he RelationShi" *etween 2tems( Can#as ;iews Windows can e s"ecified by
setting their .ro"erties. 0ach 2tem is a Can#as .ro"erty ( that s"ecify the Can#as on which the item is
dis"layed with which inturn as a Window .ro"erty ( that s"ecify the Window in which it is dis"layed atleast
%ne Can#asS;iew has to be $ssigned to each Window in a &orm.
!y"es %f Can#ases :-
1 Content Can#as --
2t is by default. 2t is the base #iew that occu"ies the entire content "ain of the window in which it is
dis"layed. $tleast %ne Content Can#as ;iew must be define for each Window that is Created( more than
%ne content Can#as ;iew can be assign at the same Window the Design !ime( but only %ne of them is
Dis"layed in the Window at Run!ime.
) Stac3ed Can#as --
2t is dis"layed in the Window on the !o" %R Stac3ed on the contents Can#as ;iew assigned in the same
Window.
/ 9orizental @ ;ertical !oll*ar Can#as --
!hese Can#as are used create !ool*ars for indi#idual Windows. 9orizantal !ool*ars are dis"layed at
the !o" of the Window ?ust under the +enu*ar.
;irtual !ool*ars are dis"layed along the 5eft Side of the Window.
Changing %f !he Can#as !y"e --
Choose Can#as :ame on the %b?ect :a#igator,%: and set its .ro"erty.
Content
Can#as ;iew !y"e - Stac3ed
;ertical !ool*ar
9orizental !ool*ar
Creation of 9orizantal !ool*ar :-
1 Creation %f Can#as --
Choose Can#as ;iew from the %b?ect :a#igator ,%: and Double Clic3 on it.
) Change the Can#as !y"e to 9orizantal !ool*ar by Setting its .ro"erty .
Select the named Can#as and shift out to 5ay%ut 0ditor ,50 and ad?ust the size of Can#as as that of the
!ool*ar by Dragging the +ouse.
Design the 9orizantal !ool*ar as follow :
*uilt-2n .rocedures
&irstSRecordE -- !o na#igate to the &irst Record.
:eCtSRecordE -- !o na#igate to the :eCt Record.
5astSRecordE -- !o na#igate to the 5ast Record.
.re#iousSRecordE -- !o na#igate to the .re#ious Record.
0CecuteS4ueryE -- !o 0Cecute the 4uery.
Commit -- !o Sa#e the Changes.
:eCtS*loc3 -- !o :a#igate to the :eCt *loc3.
.re#iousS*loc3 -- !o :a#igate to the .re#ious *loc3.
Remo#eSRecord -- !o Delete the Current Record.
0CitS&orm -- !o 0Cit from the Current Record.
0nterS4uery -- !o 0nter the 4uery.
ClearS*loc3 -- !o Clear the Contents of the *loc3.
7oS2tem ,2tem :ame -- !o 7o!o a .articular 2tem.
7oS*loc3, A*loc3:ameA -- !o 7o!o a Select *loc3.
0CitS&orm -- !o 0Cit the &orm.
-- Commit is / !y"es.
1 :o Commit ) as3 Commit / Do Commit
3 %(en2Buttn2Pressed 4
.ro"erty %f &orm +odule
+enu +odule -- Default & Smart*ar.
Master-Deta&l Relat&n
.rocedure :-
1 Create +aster *loc3 ,De"t.
) Create another *loc3 ,0m
/ &rom the Data *loc3 Wizard clic3 on Create Relation with a s"ecify *utton( .arent !able should be
Right and Child !able
Should be 5eft.
:ote :-
!wo *loc3s are "laced on the same Can#as. &rom the Run &orm 4uerying of Records can be done by
s"ecifying the condition in the +aster bloc3( which $utomatically 4ueries the cores"onding Records in the
detail *loc3.
!o $dd a Record &irst Record has to be $dded to the +aster bloc3( that is De"t ( then to the Detail *loc3
that is 0m" (
While Deleting the Records &irst Records are to be Deleted from the Detail *loc3 and then from the +aster
*loc3. Since the default Delete .ro"erty is :on-2solated.
Creating Relation through Reltions :odes of the %b?ect :a#igater.
1 Create +aster*loc3 De"t.
) Create Detail*loc3 0m".
Without establish in the Goin( Choose Relations from the De"t *loc3. Which dis"lay the Dialog *oC.
Detail *loc3 - 0m"
Goin Condition - Child !able. Column I .arent !able . Column
PL / SQL L&*rar&es
Collection of .rocedures & &unctions & .ac3ages.
%(en2Buttn2Press
declare
ff number :I1E
n numberE
begin
C :I :nE
for i in 1..C
loo"
ff :I ff K iE
end loo"E
f :I ff E
end E
SSSSSSSSSSSSSSSSSSSSSS
1 Create a Contro *loc3
) Select *loc3 -- 5ay%ut 0ditor ,50
.ro". a b
Creation %f 5ibrary :-
1 Choose 5ibraries :ode from the %b?ect :a#igator ,%: & Double Clic3 on it.
) Double Clic3 on .rogram1nits Which Dis"lays a Dialog *oC.

Choose .rocedure & gi#e :ame as &act.
.rocedure fact is
f number : I 1E
" numberE
begin
" : I : aE
for i in 1.."
loo"
f : I f K iE
end loo"E
: b : I f E
endE
Com"ile the Code & Return *ac3 to %b?ect :a#igator ,%:.
Choose the Created 5ibrary from %: & &ile -- Sa#e , . .55
7etting %f 5ibrary
Choose $ttached 5ibraries from &orm +odule of %: & Double Clic3 on it.
!y"e the 5ibrary :ame %R Choose from &ind & Select $ttach Radio *utton .
Pus(Buttn
WhenS*uttonS.ress
.rocedure :ame5
Re$rts
-- to 7enerate Re"orts
-- 0Ctraction of Data from the Data*ase & .rint it in a .redefined &ormat.
Re"ort 5ay%ut
1 .age 9eader
) Column 9eader
/ .age &ooter
.age 9eader -- is .rinted at the !o" of 0ach & 0#ery .age.
Column 9eading -- is .rinted for 0ach & 0#ery Record.
.age &ooter -- is .rinted at the *ottom of 0ach & 0#ery .age.
Data 7rou"ing :-
7rou"ing of Selected Data.
1 Data on a Common field whose #alue is not 1ni'ue.
) Data should be Sorted on the &ield on which 7rou"ing is done.
Wor3ing With Re"orts :-
Start -- .rograms -- De#)>>> -- Re"orts Designer.
Creation %f Re"orts --
1 Data +odel 0diter
) Re"ort Wizard
!y"es %f Re"orts
1 !abular ) &orm / 7rou" 5eft 6 7rou" $bo#e
8 +atriC B +ailing 5abel = +atriC 7rou" D &orm 5i3e
" Run "(e Re$rt On Canvas
%(en2Buttn2Pressed
RunS.roduct,R0.%R!S ( A shSre" A( SH:C9R%:%1S( R1:!2+0( &250SHS!0+(1(:155E
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
0C:-
1 W.$... to acce"t a no. and "rint the factorial #alue

a b
declare
aa numberE
f numberE
begin
f :I 1E
aa : I : a E
for i in 1..aa
loo"
f : I f K i E
end loo" E
: b : I f E
end E
Creation %f Chec3*oC
.ro"erty of Chec3*oC --
:ame -- C1 :ame -- C)
5abel -- +anager 5abel -- Cler3
;alue when Chec3ed -- 1 ;alue when Chec3ed -- 1
;alue when 1n-Chec3ed -- > ;alue when 1n-Chec3ed -- >
C1

%(en2C(ec!B,2C(anged
if : c1 I 1 then
: desig : I A+anagerA E
else
: desig : I A A E
end ifE

%(en2C(ec!B,2C(anged
if : c) I 1 then
: desig : I ACler3A E
else
: desig : I A A E
end ifE
%(en2C(ec!B,2C(anged
if : c/ I 1 then
: desig : I A!y"iestA E
else
: desig : I A A E
end ifE
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
0C:- "r&gger
%(en26e/2.r'2+nstance
setSwindowS"ro"erty, &ormsS+diSwindow( "osition(8(1>E
setSwindowS"ro"erty, &ormsS+diSwindow( windowSstate(+aCimizeE
setSwindowS"ro"erty, &ormsS+diSwindow(!itle( A my own mdi window A E
setSwindowS"ro"erty, A window > A( "osition( 1>( )> E
setSwindowS"ro"erty, A window A ( title( A child window A E


@@7R$:!2:7 .0R+2SS2%:S !% $:%!90R 1S0R
1.CR$0!0 :0W 1S0R *H 5%72: 2: SHS!0+@+$:$70R
).CR0$!0 1S0R 1S0R:$+0 2D0:!2&20D *H .$SSW$RD
/.7R$:! C%::0C!(R0S%1RC0 !% 1S0R:$+0
6.S9%W1S0R
8.C%::0C! 1S0R :$+0@.$SSW$RD
B.S9%W 1S0R
=.C%::0C! SC%!!@!270R
D.7R$:! $55 %: O!$*50:$+0- !% 1S0R :$+0
<.C%::0C! 1S0R :$+0 @.$SSW$RD
1>.S050C! K &R%+ O1S0R:$+0-. O!$*50:$+0-
11.S050C! K &R%+ SC%!!.0+.E
foreign 3ey
1.create table shi#a sno number ,)( name #archar,1)E
).create table #ishnu,rno number,) referances shi#a,sno(de"t #archar,1)E
Goins
e'ui?oin
!he "rocess of ?oing two or more tables using assignment o"erator
1.select Ocolumname- from table names where condition
select sno(sname (rno(de"t from shi#a(#ishnu where shi#a.snoI#ishnu.rnoE
non e'ui ?oins
!he "rocess of ?oing two or more tables without using assignment o"erator.
Select ename(?ob(sal grade(losal(hisal from em"(salgrade where sal between losal and hisalE
Create #iew O#iewname- as O'uery-
Create #iew #i#a as select K from em" where de"tnoI/>E
7rant select to Ousername- on O#iewname-

%rder by
Select K from em" order by enameE @@ascending order
Select K from em" order by ename descE @@ descending order
Select lower,dname from de"tE
select ename from em" where enameIu""er,A&enameAE
select initca",dname(initca",loc from de"tE @@ to dis"lay first letter ca"s
create table ##,sno(sname(smar3s(class as select em"no(ename(sal(de"tno from em"E
@@ wrong @@ insert into ## #alues as select em"no(ename(sal(de"tno from em" where de"tnoI)>E

Вам также может понравиться