SQL for Tables [message #653079] |
Mon, 27 June 2016 06:11 |
|
Hi,
We have grown up by mugging up Multiplication Tables. Trying to do the same in SQL.
Create a Multiplication Table in Following Format. Don't want to use PLSQL.
User Inputs : A, B are user parameter inputs.
-----------------------------------------------------------------------------------
A * B = C
Example: A = 1
B=3
Output:
1 * 1 = 1
1* 2 = 2
1* 3 = 3
Javed
[Updated on: Mon, 27 June 2016 06:12] Report message to a moderator
|
|
|
Re: SQL for Tables [message #653081 is a reply to message #653079] |
Mon, 27 June 2016 06:23 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Is this a college homework question?
What SQL have you tried so far? I would start by using CONNECT BY LEVEL to generate some rows:orclz>
orclz> select rownum from dual connect by level <=12;
ROWNUM
----------
1
2
3
4
5
6
7
8
9
10
11
12
12 rows selected.
orclz>
|
|
|
Re: SQL for Tables [message #653082 is a reply to message #653081] |
Mon, 27 June 2016 06:43 |
|
Thanks, This is count . Wanted table of the number where i am taking two inputs first number and second number like if its A=2 and B=5 the result will be
2 * 1= 2
2 * 2= 4
2 * 3= 6
2 * 4= 8
2 * 5= 10
Hope i am clear.
|
|
|
|
|
Re: SQL for Tables [message #653085 is a reply to message #653084] |
Mon, 27 June 2016 06:49 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
I've already shown you how to generate values that you can use for one operand. You should be able to generate the other operand, and multiply them together.
|
|
|
Re: SQL for Tables [message #653086 is a reply to message #653084] |
Mon, 27 June 2016 06:52 |
|
Sorry forgot to post what i have tried already here it is ...
declare
n number(5);
i number(2);
m number(5);
limit number(5);
begin
i:=1;
n:=&n; -- The number for which multiplication table should be printed.
limit:=&l; -- This specifies the limit of the table.
dbms_output.put_line('Multiplication table for '|| n);
for i in 1..limit
loop
m:=n*i;
dbms_output.put_line(n||'*'||i||'='||m);
end loop;
end;
Its not college project Something i am trying to write , not urgent , not required too. I am trying.
Javed A. Khan
|
|
|
|
|
|
|
Re: SQL for Tables [message #653107 is a reply to message #653091] |
Mon, 27 June 2016 21:01 |
|
Okay tried again. It wasn't correct . you are right.
with aaa as ( select :x as x,:y as y from dual)
SELECT x||'*'||level || ' = ' ||round(exp(ln(x) + ln(level))) as output from aaa connect by level <= y;
|
|
|
|
|
|
Re: SQL for Tables [message #653111 is a reply to message #653110] |
Mon, 27 June 2016 21:11 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
javed.khan wrote on Mon, 27 June 2016 19:04I meant this
SELECT :myval || '*' || ROWNUM || '=' || ROWNUM * :myval
FROM DUAL
CONNECT BY LEVEL <= :myval;
SQL> SELECT :myval || '*' || ROWNUM || '=' || ROWNUM * :myval
FROM DUAL
CONNECT BY LEVEL <= :myval; 2 3
SP2-0552: Bind variable "MYVAL" not declared.
SQL>
Consider to actually test code before posting here.
|
|
|