Sei sulla pagina 1di 2

create table book(bid number,btitle char(20), noc number, ac number);

create table member(mem_id number,name char(20),address char(50),no_of_cards


number,no_of_free_cards number);

create table issued(mem_id number, book_id number);

SQL> insert into member values(1,'navein','chennai',5,3);

SQL> insert into member values(2,'goutham','delhi',6,0);

SQL> insert into member values(3,'sanjay','chennai',7,2);

SQL> alter table book modify btitle char(50);

SQL> insert into book values(1,'Computer Architecture',20,7);

SQL> insert into book values(2,'Data Structures',15,4);

SQL> insert into book values(3,'Mathematics',30,17);

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------

q1) SQL> select * from member where no_of_free_cards=0;

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);

q3) SQL> alter sequence book_id maxvalue 15;

q4) SQL> select distinct member.mem_id,name from member,book,issued where


member.mem_id=(select mem_id from issued where book_id=2);

q5) SQL> create view jview(jid,jname,jadd,jnc,jnfc) as select


mem_id,name,address,no_of_cards,no_of_free
_cards
2 from member where address='chennai';

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------------------------------------------------

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

PL/SQL procedure successfully completed.

Potrebbero piacerti anche