Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of printing different triangle shapes with SQL

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report