Welcome to Data Warehousing Flying Bee

Monday 4 June 2012

Looping


IF CONDITION
                Conditional Statements
                ======================
1. Simple if:
=========
if (condition) then
        stmts;
end if;

2.If..Else:
=======
                if (condition) then
                            stmts;
                else
                            stmts;
                end if;

3. Else if Ladder:
=============
                if (condition) then
                           stmts;
                elsif (condition) then
                           stmts;
                elsif (condition) then
                           stmts;
                else
                         stmts;
                end if;
------------------------------------------------------------------------------
DECLARE
                x int:=&num1;
BEGIN
                if (x mod 2=0) then
                                dbms_output.put_line('Even Number');
                else
                                dbms_output.put_line('Odd Number');
                end if;
                --chr(9) tab space
                --chr(10) is a line feed character
                dbms_output.put_line(chr(10)||'End of the Condition');
END;
/
------------------------------------------------------------------------------
declare
                x int:=&x;
begin
                if (x>0) then
                                dbms_output.put_line('Positive Number');
                elsif (x<0) then
                                dbms_output.put_line('Negative Number');  
                else
                                dbms_output.put_line('Neutral Number (0)');
                end if;
end;
/
------------------------------------------------------------------------------
declare
                x int:=&num1;
                y int:=&num2;
                z int:=&num3;

begin
                if (x > y and x > z) then
                                dbms_output.put_line('X is the Biggest');
                elsif (y > z) then
                                dbms_output.put_line('Y is the Bigggest');
                else
                                dbms_output.put_line('Z is the Biggest');
                end if;
end;
/

--USING BOOLEAN
declare
                x boolean;
begin
                if x=true then
                     dbms_output.put_line('x value is true');
                elsif x=false then
                     dbms_output.put_line('x vlaue is false');
                end if;
end;
/
------------------------------------------------------------------------------
declare
                x int:=&x;
begin
                if (x < 10) then
                                dbms_output.put_line('Single Digit');
                elsif (x>9 and x<100) then
                                dbms_output.put_line('Double Digit');
                elsif (x>99 and x<1000) then
                                dbms_output.put_line('Triple Digit');
                else
                                dbms_output.put_line('More Than 3');                          
                end if;
end;
/
------------------------------------------------------------------------------
DECLARE
   x int;
BEGIN
   x:=&x;
   If (x mod 2 = 0) Then
      dbms_output.put_line('Even Number');
   Else
      dbms_output.put_line('Odd Number');
   End If;
END;
------------------------------------------------
DECLARE
    x1 int;
    x2 int;
    x3 number(2);
BEGIN
    x1:=&Number1;
    x2:=&Number2;
    x3:=&Number3;
    If(x1>x2 And x1 > x3)Then
       dbms_output.put_line('x1 is the biggest number');
    elsif (x2>x3) Then
       dbms_output.put_line('x2 is the biggest number');
    else
       dbms_output.put_line('x3 is the biggest number');     
    End If;
END;
--------------------------------------------------
DECDECLARE
   uid varchar2(10);
   pwd varchar2(10);
BEGIN
   uid:='&User_id';
   pwd:='&Password';
   If (uid<>'abcd' OR pwd<>'1234') Then
      dbms_output.Put_line('Invalid UserId/Password');
   else
      dbms_output.put_line('Welcome...');
   End If;
END;

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Justin Bieber, Gold Price in India
Flying Bee Fish swimming from right to left Bat flying really fast