Kimball Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

SQL Help !!!!

2 posters

Go down

SQL Help !!!! Empty SQL Help !!!!

Post  Afaf Thu Sep 20, 2012 7:52 pm

Im making a multiplication table for 5 and 6. im using this statement:
declare
a number(2):=5;
b number(2):=6;
c number(2);
begin
for c in 1..5
loop
dbms_output.put_line(a||'*'||c||' = '||a*c);
dbms_output.put_line(b||'*'||c||' = '||b*c);
end loop;
end;
/
My required results are:
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30

Im getting

5 * 1 = 5
6 * 1 = 6
5 * 2 = 10
6 * 2 = 12.....

Any idea how I can fix this?

I tried:
declare
a number(2):=5;
b number(2):=6;
c number(2);
begin
for c in 1..5
loop
dbms_output.put_line(a||'*'||c||' = '||a*c);
end loop;
loop
dbms_output.put_line(b||'*'||c||' = '||b*c);
end loop;
end;
But this statement just hangs... it never shows the results.. froze my PC twice..

THanks

Afaf

Posts : 14
Join date : 2012-09-18

Back to top Go down

SQL Help !!!! Empty Re: SQL Help !!!!

Post  yuldashev Fri Sep 21, 2012 9:04 am

Hi Afaf,

You can do -

begin
for x in 5..6
loop
for c in 1..5
loop
dbms_output.put_line(x||'*'||c||' = '||x*c);
end loop;
end loop;
end;
/

or

begin
for x in (select 5 from dual
union all
select 6 from dual)
loop
for c in 1..5
loop
dbms_output.put_line(x||'*'||c||' = '||x*c);
end loop;
end loop;
end;
/

or

declare
a number(2):=5;
b number(2):=6;
c number(2);
begin
for c in 1..5
loop
dbms_output.put_line(a||'*'||c||' = '||a*c);
end loop;
for c in 1..5
loop
dbms_output.put_line(b||'*'||c||' = '||b*c);
end loop;
end;
/

Thanks,
Alisher
www.streebo.com
yuldashev
yuldashev

Posts : 13
Join date : 2012-08-14
Location : Ottawa, Canada

Back to top Go down

SQL Help !!!! Empty Re: SQL Help !!!!

Post  Afaf Mon Sep 24, 2012 11:04 pm

Thanks for replying......

Afaf

Posts : 14
Join date : 2012-09-18

Back to top Go down

SQL Help !!!! Empty Re: SQL Help !!!!

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum