Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------
q2) SQL> create sequence book_id start with 1 increment by 2 minvalue 1 maxvalue
20;
SQL> insert into book values(book_id.nextval,'Physics',25,12);
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
PL/SQl _Cursors :
SQL> ed
Wrote file afiedt.buf
1 declare
2 c_bid book.bid%type;
3 c_btitle book.btitle%type;
4 c_noc book.noc%type;
5 c_ac book.ac%type;
6 ex exception;
7 cursor book_cur IS
8 select bid,btitle,noc,ac from book;
9 begin
10 open book_cur;
11 begin
12 loop
13 begin
14 fetch book_cur into c_bid,c_btitle,c_noc,c_ac;
15 exit when book_cur%notfound;
16 if(c_btitle='Computer Architecture') then
17 c_noc:=c_noc + 15;
18 update book set noc=c_noc where book.btitle='Computer Architecture' and
c_bid=bid;
19 dbms_output.put_line('Book Id :' || c_bid ||'Book Title' || c_btitle || 'No
of copies : '|| c_no
20 continue;
21 end if;
22 exception
23 when ex then
24 dbms_output.put_line('Error!');
25 continue;
26 end;
27 end loop;
28 end;
29 close book_cur;
30 dbms_output.put_line('No of rows affected : ' || sql%rowcount);
31* end;
32 /
Book Id :1Book TitleComputer Architecture No of
copies : 95Available copies 7
No of rows affected : 1