The challenge is to make a SQL query to draw a Star Pattern in Diamond Shape.
Drawing Star Pattern using SQL is not why Oracle is used but it is always good to try new thing when someone gives you a challenge.
I have written following SQL to draw Above Star Pattern.
19 rows selected.
Please use comment box to share your SQL Queries which draws Following Star Pattern.
More SQL Puzzles:
- SQL Puzzle - Transpose Rows and Shift Values among columns
- Graph Shortest Path Solution by SQL
- Sorting Versions stored in Varchar2 Column
- SQL Puzzle - Grouping Deals
- SQL Puzzle - Consecutive Wins
- SQL Puzzle - Issue Tracker
- SQL Interview Question Answers
Drawing Star Pattern using SQL is not why Oracle is used but it is always good to try new thing when someone gives you a challenge.
I have written following SQL to draw Above Star Pattern.
SQL> set pages 100
SQL> SELECT LPAD (' ', 10 - LEVEL, ' ')
2 || LPAD ('*', LEVEL, '*')
3 || LPAD ('*', LEVEL - 1, '*')
4 "Star Pattern in Diamond Shape"
5 FROM DUAL
6 CONNECT BY LEVEL <= 10
7 UNION ALL
8 SELECT LPAD (' ', LEVEL, ' ')
9 || LPAD ('*', 10 - LEVEL, '*')
10 || LPAD ('*', 9 - LEVEL, '*')
11 FROM DUAL
12 CONNECT BY LEVEL <= 9;
Star Pattern in Diamond Shape
------------------------------------------------------------
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
19 rows selected.
Please use comment box to share your SQL Queries which draws Following Star Pattern.
More SQL Puzzles:
- SQL Puzzle - Transpose Rows and Shift Values among columns
- Graph Shortest Path Solution by SQL
- Sorting Versions stored in Varchar2 Column
- SQL Puzzle - Grouping Deals
- SQL Puzzle - Consecutive Wins
- SQL Puzzle - Issue Tracker
- SQL Interview Question Answers
Wow..Loved that ...
ReplyDelete