We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I’m encountering an issue while running my query on HackerRank. The same query works perfectly in Oracle SQL Developer, but when I try to run it on HackerRank, I get an error. The query is designed to find prime numbers up to 1000 and list them separated by &.
Here is my query:
WITH numbers AS (
SELECT LEVEL AS num
FROM dual
CONNECT BY LEVEL <= 1000
),
prime_candidates AS (
SELECT num
FROM numbers
WHERE num > 1
),
primes AS (
SELECT num
FROM prime_candidates np
WHERE NOT EXISTS (
SELECT 1
FROM prime_candidates pc
WHERE pc.num < np.num
AND MOD(np.num, pc.num) = 0
)
)
SELECT LISTAGG(num, '&') WITHIN GROUP (ORDER BY num) AS prime_numbers
FROM primes;
It works fine in Oracle SQL Developer, but on HackerRank, I get the error:
output:-
SP2-0734: unknown command beginning "prime_cand..." - rest of line ignored.
SP2-0734: unknown command beginning "primes AS ..." - rest of line ignored.
ORA-00942: table or view does not exist
Could anyone explain why I get this error on HackerRank and if there’s something wrong with my query? I am using Oracle SQL for this query.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Print Prime Numbers
You are viewing a single comment's thread. Return to all comments →
I’m encountering an issue while running my query on HackerRank. The same query works perfectly in Oracle SQL Developer, but when I try to run it on HackerRank, I get an error. The query is designed to find prime numbers up to 1000 and list them separated by &.
Here is my query:
WITH numbers AS ( SELECT LEVEL AS num FROM dual CONNECT BY LEVEL <= 1000 ),
prime_candidates AS ( SELECT num FROM numbers WHERE num > 1 ),
primes AS ( SELECT num FROM prime_candidates np
WHERE NOT EXISTS ( SELECT 1 FROM prime_candidates pc WHERE pc.num < np.num AND MOD(np.num, pc.num) = 0 ) )
SELECT LISTAGG(num, '&') WITHIN GROUP (ORDER BY num) AS prime_numbers FROM primes; It works fine in Oracle SQL Developer, but on HackerRank, I get the error:
output:-
SP2-0734: unknown command beginning "prime_cand..." - rest of line ignored. SP2-0734: unknown command beginning "primes AS ..." - rest of line ignored. ORA-00942: table or view does not exist
Could anyone explain why I get this error on HackerRank and if there’s something wrong with my query? I am using Oracle SQL for this query.