SQL1Fall 2001 Database Systems 1PL/SQL• Oracle’s procedural language. Used for triggers, storedprocedures, etc.• Overviewd...
SQL2Fall 2001 Database Systems 3PL/SQL• Cursor properties– %FOUND, %NOTFOUND : a record can/cannot be fetched from thecurs...
SQL3Fall 2001 Database Systems 5PL/SQL – exceptions• Exceptions arise when a statement causes an error.• Examples:ACCESS_I...
Upcoming SlideShare
Loading in...5
×

[Www.pkbulk.blogspot.com]dbms08

180

Published on

Introduction to database lecture# 8: This lecture is all about PL/SQL Baseic and code examples and MORE....

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
180
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

[Www.pkbulk.blogspot.com]dbms08

  1. 1. SQL1Fall 2001 Database Systems 1PL/SQL• Oracle’s procedural language. Used for triggers, storedprocedures, etc.• Overviewdeclare<declarations section>begin<executable commands>exception<exception handling>end;Fall 2001 Database Systems 2PL/SQL Exampledeclarecursor item_cursor is select * from ITEMS ;item_val item_cursor%ROWTYPE ;cnt INTEGER(5) := 0 ;beginopen item_cursor ;loopfetch item_cursor into item_val ;exit when item_cursor%NOTFOUND ;cnt := cnt + 1 ;end loop ;close item_cursor ;if (cnt > 0)then insert into item_count values(cnt) ;end if ;end ;/
  2. 2. SQL2Fall 2001 Database Systems 3PL/SQL• Cursor properties– %FOUND, %NOTFOUND : a record can/cannot be fetched from thecursor– %ISOPEN : the cursor has been opened– %ROWCOUNT : the number of rows fetched from the cursor so far– %TYPE : the data type of a column:Iname item_cursor.name%TYPE• Conditional logicif <some condition>then <some command>elsif <some condition>then <some command>else <some command>end if ;Fall 2001 Database Systems 4PL/SQL – Loops• For loop:for item_val in item_cursorloopend loop ;//note no need for open/fetch/closecursor commands in this case.• While loop:while cnt < 5loopend loop ;
  3. 3. SQL3Fall 2001 Database Systems 5PL/SQL – exceptions• Exceptions arise when a statement causes an error.• Examples:ACCESS_INTO_NULLCURSOR_ALREADY_OPENDUP_VAL_ON_INDEXINVALID_CURSORLOGIN_DENIEDNO_DATA_FOUNDNOT_LOGGED_ONTOO_MANY_ROWS – select into stmt returns morethan one rowVALUE_ERRORZERO_DIVIDEFall 2001 Database Systems 6PL/SQLdeclarecursor item_cursor is select I.iid, I.oid, count(B.bid) bidcntfrom items I, bids B where I.iid = B.iidgroup by I.iid, I.oid ;item_val item_cursor%ROWTYPE ;beginupdate owners set status = ‘B’ ;for item_val in item_cursorloopif (item_val.bidcnt > 2)then update owners set status = ‘G’where oid = item_val.oid;end if;end loop ;end ;/

×