top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

how to write a query that results an pyramid structure in Oracle SQL

+2 votes
1,740 views

suppose if i give '12345'

output should be:

1
12
123
1234
12345
1234
123
12
1

posted Sep 16, 2014 by Archana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
 
Best answer

i'm not sure in SQL query, nut it can achieved from PLSQL,:

declare
str varchar2(10):='12345';
begin
for i in 1..length(str)
loop
dbms_output.put_line(substr(str,1,i));
end loop;
for i in reverse 1..length(str)-1
loop
dbms_output.put_line(substr(str,1,i));
end loop;
end;

answer Sep 16, 2014 by Arun Gowda
0 votes

SELECT RPAD('12345',LEVEL*1,'1') FROM DUAL
CONNECT BY LEVEL<=5
union all
SELECT RPAD('12345',(5-LEVEL)*1,'1') FROM DUAL
CONNECT BY LEVEL<=5;

answer Jul 26, 2017 by anonymous
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...