Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of printing different triangle shapes with SQL

Shulou Source: shulou.com Published: 2022-06-01 04:27:50 11月13日 Update

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

Tags: Variable condition output method article different shape triangle two value content at the same time character data friend type ribbon industry grammar information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Apple Linux Xiaomi