Write PL/SQL block that asks user to input first number, second number and an arithmetic operator (+, -, *, or /). If operator is invalid, throw and handle a user-defined exception. If second number is 0 and the operator is /, handle ZERO_DIVIDE predefined server exception.

What will be an ideal response?


```
SQL> DECLARE
2 bad_op EXCEPTION;
3 n1 NUMBER := &number1;
4 n2 NUMBER := &number2;
5 op VARCHAR2(1) := '&operator';
6 res NUMBER;
7 BEGIN
8 IF op<>'+' AND op<>'-' AND op <>'*' AND op<>'/' THEN
9 RAISE bad_op;
10 END IF;
11 IF op = '+' THEN
12 res := n1 + n2;
13 ELSIF op = '-' THEN
14 res := n1 - n2;
15 ELSIF op = '*' THEN
16 res := n1 * n2;
17 ELSIF op = '/' THEN
18 res := n1 / n2;
19 END IF;
20 DBMS_OUTPUT.PUT_LINE(n1 || op || n2 || '=' || res);
21 EXCEPTION
22 WHEN bad_op THEN
23 DBMS_OUTPUT.PUT_LINE('No such math operator: ' || op);
24 WHEN ZERO_DIVIDE THEN
25 DBMS_OUTPUT.PUT_LINE('Cannot divide by zero');
26 END;
27 /
Enter value for number1: 3
Enter value for number2: 5
Enter value for operator: +
3+5=8

PL/SQL procedure successfully completed.

SQL> /
Enter value for number1: 3
Enter value for number2: 5
Enter value for operator: ?
No such math operator: ?

PL/SQL procedure successfully completed.

SQL> /
Enter value for number1: 3
Enter value for number2: 5
Enter value for operator: /
3/5=.6

PL/SQL procedure successfully completed.

SQL> /
Enter value for number1: 3
Enter value for number2: 0
Enter value for operator: /
Cannot divide by zero

PL/SQL procedure successfully completed.
```

Computer Science & Information Technology

You might also like to view...

Select the statement below that would open a text file for output.

(A) ``` Dim sw As IO.StreamWriter = IO.File.OpenText("IncomeData.txt") ``` (B ``` Dim sw As IO.StreamWriter = IO.File.CreateText(IncomeData.txt") ``` (C) ``` Dim sr As IO.StreamReader = IO.File.OpenText("ncomeData.txt" ``` (D)``` Dim sr As IO.StreamReader = IO.File.AppendText("IncomeData.txt") ```

Computer Science & Information Technology

How many constructors does the class Exception have?

A. zero B. one C. two D. three

Computer Science & Information Technology

You can use high-capacity memory cards and higher _________________________ counts to take more images at a much higher resolution.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Define is an example of a Boolean operator

Indicate whether the statement is true or false

Computer Science & Information Technology