****************************
TO COMMENT A CODE
****************************
(--) ---->Single line commentTO COMMENT A CODE
****************************
(/* */)-->Multiple line comment
--------------------------------------
****************************
IF STATEMENT
****************************
IF STATEMENT
****************************
/*GREATEST AMONG THREE (USE OF IF)*/
DECLARE
A 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
****************************
declareLooping using EXIT WHEN statement
****************************
counter 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
****************************
declareLooping using WHILE
****************************
counter 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
****************************
declareLooping using WHILE BUT
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
****************************
declareLooping using FOR INCREMENT SINGLE
****************************
counter1 number(2);
begin
FOR COUNTER1 IN 1..10
loop
DBMS_OUTPUT.PUT_LINE('the count is'||counter1);
end loop;
end;
/
-----------------------------------------
****************************
LOOPING USING GOTO
****************************
DECLARELOOPING USING GOTO
****************************
A 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
****************************
DECLAREUsing NULL as a statement
****************************
v 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