top of page

Write a query to print the Inverted triangle in Oracle,MySql

Updated: Mar 18, 2021


Input: N = 20

Output:



Query In Oracle:



select    rpad('*', level*2, ' *')    from   dual  connect by level <= 20;


Here level refer to N = 20, you can change according to you.


Query In MySql:



with tree (number)
AS
(
select 1 AS nr
UNION ALL 
select number+1 AS nr FROM tree WHERE number <= 19
)

select 
REPLICATE('* ',number)
 from tree
Order by number desc




Comments


bottom of page