Chapter 2 PL/SQL Concepts

1)In order to calculate the area of a circle, the circle’s radius must be squared and then multiplied by π. Write a program that calculates the area of a circle. The value for the radius should by provided with the help of a substitution variable. Use 3.14 for the value of π. Once the area of the circle is calculated, display it on the screen.
A1: Answer: Your answer should look similar to the following:
SET SERVEROUTPUT ON 
DECLARE 
   v_radius NUMBER := &sv_radius; 
   v_area NUMBER; 
BEGIN 
   v_area := POWER(v_radius, 2) * 3.14; 
   DBMS_OUTPUT.PUT_LINE 
      ('The area of the circle is: '||v_area); 
END; 

In this exercise, you declare two variables, v_radius and v_area, to store the values for the radius of the circle and its area, respectively. ...

Get Oracle® PL/SQL® Interactive Workbook, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.