The method of printing different triangle shapes with SQL
This article mainly introduces the method of printing different triangle shapes with SQL, which has a certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
Syntax:
Declare @ variable_name DATATYPE-- first declare all variables select @ variable = WITH_ANY_VALUE with the data type (int)-- Select the variable and initialize the while CONDITION with the value-- for example, @ variable > 0begin-- start the print replicate ('*' @ variable)-- copy and insert the * character set increment/decrement in the variable times-- increment / decrement-- @ variable= @ variable+1END-- end of while loop
The first kind:
DECLARE @ var int-declare SELECT @ var = 5-initialize WHILE @ var > 0-condition BEGIN-start PRINT replicate ('*', @ var)-print SET @ var = @ var-1-decreasing END-- END
Output:
*
The second kind:
DECLARE @ var int-- declare SELECT @ var = 1-- initialize WHILE @ var