PL/SQL Control Statement Exercises: Check whether a given number is positive, negative or zero
PL/SQL Control Statement: Exercise-12 with Solution
Write a PL/SQL program to check whether a given number is positive, negative or zero.
Sample Solution:
PL/SQL Code:
DECLARE
num1 NUMBER := &get_num;
BEGIN
IF num1 < 0 THEN
DBMS_OUTPUT.PUT_LINE ('The number '||num1||' is a negative number');
ELSIF num1 = 0 THEN
DBMS_OUTPUT.PUT_LINE ('The number '||num1||' is equal to zero');
ELSE
DBMS_OUTPUT.PUT_LINE ('The number '||num1||' is a positive number');
END IF;
END;
/
Sample Output:
SQL> / Enter value for get_num: 45 old 2: num1 NUMBER := &get_num; new 2: num1 NUMBER := 45; The number 45 is a positive number PL/SQL procedure successfully completed
Sample Output:
SQL> / Enter value for get_num: 0 old 2: num1 NUMBER := &get_num; new 2: num1 NUMBER := 0; The number 0 is equal to zero PL/SQL procedure successfully completed.
Sample Output:
SQL> / Enter value for get_num: -15 old 2: num1 NUMBER := &get_num; new 2: num1 NUMBER := -15; The number -15 is a negative number PL/SQL procedure successfully completed.
Flowchart:
Improve this sample solution and post your code through Disqus
Previous: Write a PL/SQL program to display the description against a grade using CASE statement with EXCEPTION.
Next: Write a PL/SQL program to check whether a given character is letter or digit.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/plsql-exercises/control-statement/plsql-control-statement-exercise-12.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics