Sort by

recency

|

1287 Discussions

|

  • + 0 comments

    CREATE TABLE t ( Colm int, ); declare @x int =2 declare @i int declare @b int declare @z int while @x >=2 and @x<=1000 begin set @i=@x set @b=2 set @z=0 while @b < @i begin if @i%@b=0 set @z=@z+1 set @b=@b+1 end if @z=0 INSERT INTO t (colm) VALUES (@i);

    set @x=@x+1
    

    end select STRING_AGG(colm, '&') clom from t

  • + 0 comments

    WITH Numbers AS ( SELECT 2 AS num UNION ALL SELECT num + 1 FROM Numbers WHERE num < 1000 ), nonprime AS ( SELECT N1.num FROM Numbers N1 JOIN Numbers N2 ON N2.num < N1.num AND N1.num % N2.num = 0 ) SELECT STRING_AGG(CAST(num AS VARCHAR), '&') AS concatenated_value FROM Numbers WHERE num NOT IN (SELECT num FROM nonprime) OPTION (MAXRECURSION 0);

  • + 0 comments

    SET SERVEROUTPUT ON; DECLARE prime_ls SYS.ODCIVARCHAR2LIST := SYS.ODCIVARCHAR2LIST(); is_prime BOOLEAN; rst_str VARCHAR2(4000) := ''; BEGIN FOR i IN 2..1000 LOOP is_prime := TRUE; FOR J IN 2..FLOOR(SQRT(i)) LOOP IF MOD(i, j) = 0 THEN is_prime := false; exit; END IF; END LOOP; IF is_prime THEN prime_ls.EXTEND; prime_ls(prime_ls.LAST) := TO_CHAR(i); END IF; END LOOP; FOR idx in 1..prime_ls.COUNT LOOP IF idx > 1 THEN rst_str := rst_str || '&'; END IF; rst_str := rst_str || prime_ls(idx); END LOOP; DBMS_OUTPUT.PUT_LINE(rst_str); END; /

  • + 1 comment
    with recursive tmp as (
        select 2 as num
        union all
        select num + 1
        from tmp
        where num <= 1000
    )
    , primes as (
        select num
        from tmp as t1
        where not exists (select 1 
                          from tmp as t2
                          where t2.num < t1.num and t1.num % t2.num = 0)
    )
    select group_concat(num separator '&') from primes;
    
  • + 0 comments

    WITH A AS ( SELECT LEVEL AS L FROM DUAL CONNECT BY LEVEL <= 1000 ) SELECT LISTAGG(L,'&') WITHIN GROUP (ORDER BY L) FROM ( SELECT L FROM A MAIN WHERE NOT EXISTS ( SELECT 1 FROM A SUB WHERE MAIN.L>SUB.L AND MOD(MAIN.L,L)=0 AND SUB.L>1 ) AND L<>1 );