Print pyramid of GeeksforGeeks in PL/SQL

PL/SQL is a block structured language that enables developers to combine the power of SQL with procedural statements. All the statements of a block are passed to oracle engine all at once which increases processing speed and decreases the traffic.

PL/SQL extends SQL by adding constructs found in procedural languages, resulting in a structural language that is more powerful than SQL. The basic unit in PL/SQL is a block. All PL/SQL programs are made up of blocks, which can be nested within each other.

Typically, each block performs a logical action in the program. A block has the following structure:

DECLARE
    declaration statements;

BEGIN
    executable statements

EXCEPTIONS
    exception handling statements

END;

Now write a program in pl/sql which print a pyramid of string “GeeksforGeeks” shown below

Examples –

GeeksforGeeks
GeeksforGeek
GeeksforGee
GeeksforGe
GeeksforG
Geeksfor
Geeksfo
Geeksf
Geeks
Geek
Gee
Ge
G

Code –

filter_none

edit
close

play_arrow

link
brightness_4
code

--Declaraion Block
DECLARE
  
-- declaration of string as Geeksforgeeks
str VARCHAR2(100) := 'GeeksforGeeks';
  
-- len of string and num for no of rows
len VARCHAR2(100);
num NUMBER(15);
  
-- execution part begin 
BEGIN
  
--calculating length of string
num:=LENGTH(str);
  
  
-- strting of while from 
-- from num to till num>1
WHILE num>=1
    LOOP
        len:=SUBSTR(str,1,num);
        num:=num-1;
        DBMS_OUTPUT.PUT_LINE(len);
          
--ending of loop here        
END LOOP; 
  
-- end of begining block
END; 
  
-- End program

chevron_right


Output:

GeeksforGeeks
GeeksforGeek
GeeksforGee
GeeksforGe
GeeksforG
Geeksfor
Geeksfo
Geeksf
Geeks
Geek
Gee
Ge
G

Disadvantages of SQL –

  • SQL doesn’t provide the programmers with a technique of condition checking, looping and branching.
  • SQL statements are passed to Oracle engine one at a time which increases traffic and decreases speed.
  • SQL has no facility of error checking during manipulation of data.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.