TO COMMENT A CODE
(--) ---->Single line comment(/* */)-->Multiple line comment
--------------------------------------
/*GREATEST AMONG THREE (USE OF IF)*/
DECLAREA NUMBER(2):=&A;
B NUMBER(2):=&B;
C NUMBER(2):=&C;
BEGIN
IF A>B AND A>C THEN
DBMS_OUTPUT.PUT_LINE(A||'IS LARGEST');
ELSIF B>A AND B>C THEN
DBMS_OUTPUT.PUT_LINE(B||'IS LARGEST');
ELSE
DBMS_OUTPUT.PUT_LINE(C||'IS LARGEST');
END IF;
END;
----------------------------------------
/*looping using EXIT WHEN statement*/
declarecounter number(2):=0;
begin
loop
DBMS_OUTPUT.PUT_LINE('the count is'||counter);
counter:=counter+1;
exit when counter=10;
end loop;
end;
/
----------------------------------------
/*looping using WHILE */
declarecounter number(2):=0;
begin
WHILE COUNTER<=10
loop
DBMS_OUTPUT.PUT_LINE('the count is'||counter);
counter:=counter+1;
end loop;
end;
/
-----------------------------------------
/*looping using WHILE
BUT NOT INITIALIZING THE COUNTER */
declareBUT NOT INITIALIZING THE COUNTER */
counter1 number(2);
begin
WHILE COUNTER1<=10
loop
DBMS_OUTPUT.PUT_LINE('the SECOND count is'||counter1);
counter1:=counter1+1;
end loop;
end;
/
-----------------------------------------
/*looping using FOR INCREMENT SINGLE */
declarecounter1 number(2);
begin
FOR COUNTER1 IN 1..10
loop
DBMS_OUTPUT.PUT_LINE('the count is'||counter1);
end loop;
end;
/
-----------------------------------------
/*LOOPING USING GOTO*/
DECLAREA NUMBER(2):=0;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(A);
A:=A+1;
IF A>10 THEN
GOTO END_OF_LOOP;
END IF;
END LOOP;
<
DBMS_OUTPUT.PUT_LINE('THE LOOP IS END');
LOOP
A:=A-1;
DBMS_OUTPUT.PUT_LINE(A);
EXIT WHEN A<=5;
END LOOP;
END;
-----------------------------------------
/*Using NULL as a statement*/
DECLAREv NUMBER := 7;
BEGIN
IF v<5 THEN
dbms_output.put_line('less than 7');
ELSIF v>7 THEN
dbms_output.put_line('Greater than 7');
ELSE
NULL; -- Do nothing
END IF;
END;
/
No comments:
Post a Comment