如何使用SQL打印星形三角形 [英] How do I print a triangle of stars using SQL

查看:153
本文介绍了如何使用SQL打印星形三角形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上可以创建一个三角形的星形,像下面的SQL.I知道这可以很容易地在任何其他编程语言,如C,C ++,Java,但想知道它是否真的可能只是SQL或PL / SQL.I尝试在Oracle中使用双表,但无法通过它。

Is it practically possible to create a triangle of stars like this as below in SQL.I know that this could be done easily in any other programming language like C,C++,Java but want to know whether it is really possible with just SQL or PL/SQL.I tried working on it with dual table in Oracle but couldn't get through it.

  *              *
 * *             * * 
* * *    or      * * *

推荐答案

最简单的方法就是这样。

The simplest approach would be something like this. You can get more sophisticated particularly if you want to build the equilateral triangle rather than the right triangle.

SQL> ed
Wrote file afiedt.buf

  1  select rpad( '* ', level*2, '* ' )
  2    from dual
  3* connect by level <= 3
SQL> /

RPAD('*',LEVEL*2,'*')
--------------------------------------------------------------------------------
*
* *
* * *

这篇关于如何使用SQL打印星形三角形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆