Sort by

recency

|

1265 Discussions

|

  • + 0 comments

    For MySQL

    DELIMITER ##
    
    CREATE PROCEDURE pattern_print()
    BEGIN
        DECLARE i INT DEFAULT 20;
    
        WHILE i>0 DO
                SELECT IF(i = 1, "*", REPEAT("* ", i));
                SET i = i - 1;
        END WHILE;
    END##
    
    DELIMITER ;
    
    CALL pattern_print();
    
  • + 0 comments

    my sql

    delimiter $$ 
    create procedure loops()
    begin
        declare counter int default 20;
        
        while counter >0 do 
            select repeat('* ',counter);
            set counter = counter -1 ; 
            
        end while ;
    end $$ 
    
    delimiter ; 
    
    call loops();
    
  • + 0 comments

    FOR ORACLE SQL

    SELECT LEVEL AS row_num, SUBSTR('* * * * * * * * * * * * * * * * * * * ', ROWNUM) FROM DUAL CONNECT BY LEVEL <= LENGTH(' * * * * * * * * * * * * * * * * * * *');

  • + 2 comments

    declare @R int =20 while (@R>0) begin print replicate('*',@R) set @R= @R -1 end;

    the result looks fine but system says wrong answer. any suggestions why?

  • + 0 comments
    WITH RECURSIVE numbers(n) AS(
            SELECT 20
    
            UNION ALL
    
            SELECT n - 1 FROM numbers WHERE n > 1
    )
    
    SELECT REPEAT('* ', n)
    FROM numbers;