w3resource

PL/SQL Control Statement Exercises: Show the value of a same variable declared as local and global

PL/SQL Control Statement: Exercise-25 with Solution

Write a program in PL/SQL to show the value of a same variable declared as local and global.

Sample Solution:

PL/SQL Code:

<<main_label>>
DECLARE
  n NUMBER := 6;
BEGIN
  FOR n IN 1..4 LOOP
    DBMS_OUTPUT.PUT_LINE (
      'When local the value: ' || TO_CHAR(n) || ', but the value as global: ' ||
      TO_CHAR(main_label.n)  
    );
  END LOOP;
END main_label;
/

Flowchart:

Flowchart:Show the value of a same variable declared as local and global

Sample Output:

When local the value: 1, but the value as global: 6
When local the value: 2, but the value as global: 6
When local the value: 3, but the value as global: 6
When local the value: 4, but the value as global: 6

PL/SQL procedure successfully completed.

Improve this sample solution and post your code through Disqus

Previous: Write a program in PL/SQL to print 1st n numbers with a difference of 3 and starting from 1.
Next: Write a program in PL/SQL to explain the uses of nested for loop with label.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.