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 * * *
Can someone please shed somelight if anyone knows about it.
Use: select case when (A+B<=C or B+C<=A or A+C<=B) then 'Not A Triangle' when (A=B and B=c) then 'Equilateral' when (A=B AND C<>B) or (B=C AND C<>A) or (A=C AND A<>B) then 'Isosceles' else 'Scalene' end as triangle_type from TRIANGLES; Here, it will strictly check for the type of the triangles.
[Equilateral Traingle] We can make a pyramid with Oracle SQL as follows. select rpad(' ',5 -level) || rpad( '* ', level*2, '* ' ) from dual connect by level <= 5; ** Here 5 is the number of lines. Save this answer.
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,'*')
--------------------------------------------------------------------------------
*
* *
* * *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With