create table areas ( r number(2), area number (14,2));
declare
r number(5);
area number(14,2);
pi constant number (4,2):=3.14;
begin
r:=3;
while r<=7
loop
area:=pi*power(r,2);
insert into areas values(r,area );
r:=r+1;
end loop;
end;
select * from areas;
declare
r number(5);
area number(14,2);
pi constant number (4,2):=3.14;
begin
r:=3;
while r<=7
loop
area:=pi*power(r,2);
insert into areas values(r,area );
r:=r+1;
end loop;
end;
select * from areas;
please explain
ReplyDeleteWhy you take r:=r+1;
ReplyDeleteTo increment the value of radius.so we can perform the next calculation.
DeleteTo increment the value of radius.so that we can perform next calculation..
ReplyDeleteDECLARE RADIUS NUMBER; AREA NUMBER(7,2);
ReplyDeleteBEGIN
FOR RADIUS IN 3..7 LOOP AREA :=3.14*RADIUS*RADIUS;
dbms_output.put_line('Area of circle with radius '|| radius || 'is ' || area); END LOOP;
end;
How to create a table with for loop like
DeleteRADIUS AREA
---------- ----------
3 28.26
4 50.24
5 78.5
6 113.04
7 153.86
This comment has been removed by the author.
ReplyDeleteOut put
ReplyDeletedeclare
ReplyDeleter number(5);
area number(14,2);
pi constant number (4,2):=3.14;
begin
for r in 3..7
loop
area:=pi*power(r,2);
insert into Circle(RADIUS,AREA) values(r,area );
end loop;
end;
/
Write a PL/SQL code block to calculate the area of a circle for a value of radius varying from 3 to 7. Store the radius and the corresponding values of calculated area in an empty table named areas, consisting of two columns radius and area.
ReplyDelete--Find the area and perimeter of circle
ReplyDeleteDECLARE
-- Variables to store area and perimeter
area NUMBER(6, 2) ;
perimeter NUMBER(6, 2) ;
--Assigning the value of radius
radius NUMBER(1) := 3;
--Constant value of PI
pi CONSTANT NUMBER(3, 2) := 3.14;
BEGIN
--Formula for area and perimeter of a circle
area := pi * radius * radius;
perimeter := 2 * pi * radius;
dbms_output.Put_line('Area = ' || area);
dbms_output.Put_line(' Perimeter = ' || perimeter);
END;
im getting invalid charecter error
ReplyDeleteWhat is it's output
ReplyDeletenot proper output
ReplyDelete