0

The Question was to print a Right-Angled Triangle in Hacker-Rank -:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Declare @var int Select @var=1 While @var < 6 Begin Print replicate('* ',@var) ' at line 1

This was my Code but it's not working -:

Declare @var int Select @var=1 While @var < 6 Begin Print replicate('* ',@var) Set @var = @var + 1 End

  • 2
    Lots of things wrong with this including - declared variables can only be uses in stored routines(and you cannot declare user defined variables), same with while, there is no print in mysql and in mysql every statement must be terminated. Your code looks more like sql server that's just been dropped into mysql in the expectation that mysql is compatible with sql-server, – P.Salmon Jan 11 '23 at 07:29
  • Further reading - https://stackoverflow.com/questions/11754781/how-to-declare-a-variable-in-mysql https://dev.mysql.com/doc/refman/8.0/en/create-procedure.html https://dev.mysql.com/doc/refman/8.0/en/while.html – P.Salmon Jan 11 '23 at 07:31

0 Answers0