Sunday, 9 June 2013

PL/SQL program to update Table with select query

Create table place_jack (room_id varchar2(5), building varchar2(20), room_no number(5), no_of_seats number(5),description varchar2(50)) ;

Inserting values in the table:

Insert into place_jack (room_id, building, room_no, no_of_seats) values(‘p001’,’A’,101,30);
Insert into place_jack (room_id, building, room_no, no_of_seats) values(‘p002’,’B’,202,15);
Insert into place_jack (room_id, building, room_no, no_of_seats) values(‘p003’,’C’,204,35);


PL\SQL Block:

DECLARE
nos number(5);
rid varchar2(5);
BEGIN
rid:='&rid';
SELECT no_of_seats INTO nos from place_jack where room_id=rid;
if nos<20 then
update place_jack set description='fairly small' where room_id=rid;
else
if nos between 20 and 40 then
update place_jack set description='a little bigger' where room_id=rid;
else
if nos between 20 and 40 then
update place_jack set description='lots of room' where room_id=rid;
end if;
end if;
end if;
END;

No comments:

Post a Comment