In result set i should get something like the integer * by 3 , to certain limit say ex till 20, ie. till 20*3 =60 In mysql 5.X using just Sql
col1
3
6
9
12
15
..
..
..
..
In oracle we can easily do by using level clause.
In result set i should get something like the integer * by 3 , to certain limit say ex till 20, ie. till 20*3 =60 In mysql 5.X using just Sql
col1
3
6
9
12
15
..
..
..
..
In oracle we can easily do by using level clause.
In MySQL you can create a procedure to store the result in a temporary table and display it afterwards, something like this:
DELIMITER $
CREATE PROCEDURE `temp`(upto integer)
BEGIN
DROP TABLE IF EXISTS multiple;
CREATE TABLE multiple(col1 integer);
SET @i := 1;
while @i <= upto DO
set @val := 3 * @i;
set @sql := CONCAT('INSERT INTO multiple values(',@val,')');
prepare b from @sql;
execute b;
set @i := @i + 1;
end while;
select * from multiple;
end $
DELIMITER ;
call temp(20);
CONNECT BY LEVEL
is Oracle's old propriatary syntax for recursive queries.
The SQL standard uses recursive CTEs instead, supported by Oracle as of version 11.2 and by MySQL as of version 8.
with recursive numbers(number) as
(
select 3
union all
select number + 3 from numbers where number + 3 <= 20
)
select number
from numbers
order by number;
Demo: https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=b497c18f4632d4a7fe77a6a0027a08e6
I found this answer from the post https://stackoverflow.com/a/187410/9010859 and modified it to suit this requirement.
select SeqValue*3 from (SELECT
(HUNDREDS.SeqValue + TENS.SeqValue + ONES.SeqValue) SeqValue
FROM
(
SELECT 0 SeqValue
UNION ALL
SELECT 1 SeqValue
UNION ALL
SELECT 2 SeqValue
UNION ALL
SELECT 3 SeqValue
UNION ALL
SELECT 4 SeqValue
UNION ALL
SELECT 5 SeqValue
UNION ALL
SELECT 6 SeqValue
UNION ALL
SELECT 7 SeqValue
UNION ALL
SELECT 8 SeqValue
UNION ALL
SELECT 9 SeqValue
) ONES
CROSS JOIN
(
SELECT 0 SeqValue
UNION ALL
SELECT 10 SeqValue
UNION ALL
SELECT 20 SeqValue
UNION ALL
SELECT 30 SeqValue
UNION ALL
SELECT 40 SeqValue
UNION ALL
SELECT 50 SeqValue
UNION ALL
SELECT 60 SeqValue
UNION ALL
SELECT 70 SeqValue
UNION ALL
SELECT 80 SeqValue
UNION ALL
SELECT 90 SeqValue
) TENS
CROSS JOIN
(
SELECT 0 SeqValue
UNION ALL
SELECT 100 SeqValue
UNION ALL
SELECT 200 SeqValue
UNION ALL
SELECT 300 SeqValue
UNION ALL
SELECT 400 SeqValue
UNION ALL
SELECT 500 SeqValue
UNION ALL
SELECT 600 SeqValue
UNION ALL
SELECT 700 SeqValue
UNION ALL
SELECT 800 SeqValue
UNION ALL
SELECT 900 SeqValue
) HUNDREDS) as a where seqValue != 0 limit 20;