Sort by

recency

|

1268 Discussions

|

  • + 0 comments
    -- For MySQL
    
    -- Method 1: Query Based
    
    WITH RECURSIVE numbers AS (
      SELECT 20 AS i
      UNION ALL
      SELECT i - 1 FROM numbers WHERE i > 1
    )
    SELECT REPEAT('*', i) AS stars
    FROM numbers;
    
    -- Method 2: Using  stored procedure
    
    CREATE PROCEDURE p()
    BEGIN
        DECLARE i INT DEFAULT 20;
        WHILE i >= 1 DO
            SELECT REPEAT('* ', i);
            SET i = i - 1;
        END WHILE;
    END##
    
    DELIMITER ;
    
    -- To run the procedure:
    CALL p();
    
  • + 0 comments

    Declare @i int =20 while @i>0 begin print REplicate('*',@i) set @i=@i-1 end

    for ms sql server

  • + 0 comments

    with nums as ( select 1 as num union all select num + 1 from nums where num + 1 <= 20)

    select replicate('* ', num) from nums order by num desc

  • + 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();