Print pyramid of tutorialspoint in PL/SQL


PL/SQL stands for “Procedural Language extension to SQL” . It is the mixture of SQL and Procedural features provided by programming language. It was developed by Oracle Corporation in the late 1980s as procedural extension language for SQL and the Oracle relational database.

PL/SQL programs consists of blocks that can be nested and a block structure look likes this −

DECLARE
   -- it contains declaration statements
BEGIN
   -- It contains executable statements
EXCEPTIONS
   -- It contains exception handling statements
END;

Example

In PL/SQL single-line comments begin with double hyphen(--) and Multi-line comments begin with a slash-asterisk ( /* ) and end with an asterisk-slash ( */ )

--Declaration Block
   DECLARE
-- Declaration of string for tutorialspoint
   St VARCHAR2(100) := 'tutorialspoint';
-- length(len) of string and number(numb) for rows
   len VARCHAR2(100);
   numb NUMBER(15);
-- Execution part starts from here
   BEGIN
--calculating length of string
   numb:=LENGTH(St);
-- strting of while from num to till num>1
   WHILE numb>=1
   LOOP
      len:=SUBSTR(St,1,numb);
      numb:=numb-1;
      DBMS_OUTPUT.PUT_LINE(len);
   END LOOP;
-- end of begining block
END;
-- End program

Output

If we run above program then it will generate following output

tutorialspoint
tutorialspoin
tutorialspoi
tutorialspo
tutorialsp
tutorials
tutorial
tutoria
tutori
tutor
tuto
tut
tu 
t


Updated on: 09-Aug-2019

664 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements