Untitled

mail@pastecode.io avatar
unknown
sql
a month ago
1.5 kB
3
Indexable
Never
create or replace procedure check_number (input IN number)
as
begin
    if input > 0 
        then DBMS_OUTPUT.PUT_LINE ('This is a positive number.');
    elsif input < 0
        then DBMS_OUTPUT.PUT_LINE ('This is a negative number.');
    else
        DBMS_OUTPUT.PUT_LINE ('The number is zero.');
    end if;
end;
/
begin
  check_number (1);
  check_number (-1);
  check_number (0);
end;
/

create or replace procedure factorial (input IN NUMBER)
as
    counter NUMBER := input;
    fac NUMBER := input;
begin
    loop 
        if counter < 2 then 
            exit;
        end if;
        
        counter := counter - 1;
        fac := fac * counter;
    end loop;
    DBMS_OUTPUT.PUT_LINE ('The factorial of ' || input || ' is ' || fac);
end;
/
begin
  factorial (5);
end;
/

create or replace procedure total (input IN NUMBER)
as
    counter NUMBER := 1;
    tot NUMBER := input;
begin
    loop 
        if counter >= input then 
            exit;
        end If;
        
        tot := tot + counter;
        counter := counter + 1;
    end loop;
    DBMS_OUTPUT.PUT_LINE ('The total is ' || tot);
end;
/
begin
  total (5);
end;
/

create or replace procedure even_number (input IN NUMBER)
as
    counter NUMBER := 1;
begin
    loop 
        if counter > input then
            exit;
        elsif MOD(counter, 2) = 0 then 
            DBMS_OUTPUT.PUT_LINE (counter);
        end if;
        counter := counter + 1;
    end loop;
end;
/
begin
  even_number (6);
end;
/
Leave a Comment