Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Oracle. How to get mock data using SQL?

I need to get dummy data using SQL – with 10 rows and 10 columns or 100×100 or other arbitrary number.

I was thinking of doing it like this:

    select
        (select * from
                (
                    select     level lvl
                    from       dual
                    connect by level <= 10
                )
            pivot (
                max(lvl)
                for lvl in (1,2,3,4,5,6,7,8,9,10)
            )
        )
    from dual
    connect by level <= 10

but this code throws an error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is it possible to do this with a single SQL query?

And if not, what is the preferable way to do this?

>Solution :

Your current construction is:

select ( select < 10 columns > ... )
from dual
connect by level <= 10

Oracle is expecting a single column in the subquery, not 10 (or 100).

You don’t need a subquery though, you can do:

select * from
(
    select     level lvl
    from       dual
    connect by level <= 10
)
pivot (
    max(lvl)
    for lvl in (1,2,3,4,5,6,7,8,9,10)
)
connect by level <= 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10

fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading