select '&START_NUM' + level - 1 "Number"
from dual
connect by level <= '&END_NUM' - '&START_NUM' + 1
create table numbers (value number);
declare
x number;
begin
for x in '&start_num' .. '&end_num'
loop
insert into numbers values (x);
end loop;
end;
/
DECLARE
-- declare variable num
num NUMBER(3) := 1;
sum1 NUMBER(4) := 0;
BEGIN
WHILE num <= &5 LOOP
-- display odd number
dbms_output.Put_line(num);
-- the sum of all odd numbers
sum1 := sum1 + num;
--next odd number
num := num + 2;
-- end loop
END LOOP;
dbms_output.Put_line('Sum of all odd numbers is '|| sum1);
END;
/
DECLARE
-- Declare variable n, s, r, len
-- and m of datatype number
n NUMBER := &print_num;
r NUMBER;
BEGIN
-- Calculating modulo
r := MOD(n, 2);
IF r = 0 THEN
dbms_output.Put_line('This is an '||'Even'||' Number');
ELSE
dbms_output.Put_line('This is an '||'Odd'||' Number');
END IF;
END;
--End program
/
CREATE TYPE number_row_type AS OBJECT
(
num NUMBER
);
CREATE TYPE number_set_type AS TABLE OF number_row_type;
CREATE OR REPLACE FUNCTION number_range(p_start IN PLS_INTEGER, p_end IN PLS_INTEGER)
RETURN number_set_type
PIPELINED
IS
out_rec number_row_type := number_row_type(NULL);
BEGIN
FOR i IN p_start .. p_end LOOP
out_rec.num := i;
pipe row(out_rec);
END LOOP;
END number_range;
/
No comments:
Post a Comment