1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

SQL Query for Prime Numbers?

Discussion in 'SQL PL/SQL' started by Bagavathi, Dec 26, 2014.

  1. Bagavathi

    Bagavathi Active Member

    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    80
    Is it possible to retrieve first 100 prime numbers using SQL Query? If so kindly share the query.
     
  2. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
    select l prime_number

    from (select level l from dual connect by level <= 100)

    , (select level m from dual connect by level <= 100)

    where m<=l

    group by l

    having count(case l/m when trunc(l/m) then 'Y' end) = 2

    order by l
     
    Bagavathi likes this.