Basic Oracle Concepts and Programming Question:
Download Job Interview Questions and Answers PDF
How To Use "FOR" Statements in Oracle?
Answer:
If you have a block of codes to be executed repeatedly over a range of values, you can use the "FOR ... LOOP" statement. Here is a sample script on FOR statements:
DECLARE
total NUMBER := 0;
BEGIN
FOR i IN 1..10 LOOP
total := total + i;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Total: ' || TO_CHAR(total));
END;
Note that temporary variable "i" used in the FOR loop needs no declaration. This script should print this:
Total: 55
DECLARE
total NUMBER := 0;
BEGIN
FOR i IN 1..10 LOOP
total := total + i;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Total: ' || TO_CHAR(total));
END;
Note that temporary variable "i" used in the FOR loop needs no declaration. This script should print this:
Total: 55
Download Oracle Database Interview Questions And Answers
PDF
Previous Question | Next Question |
How To Use "WHILE" Statements in Oracle? | What Is NULL in PL/SQL? |