在PL / SQL中打印tutorialspoint的金字塔
PL/SQL代表“SQL的过程语言扩展”。它是编程语言提供的SQL和过程功能的混合。它是由OracleCorporation在1980年代后期开发的,它是SQL和Oracle关系数据库的过程扩展语言。
PL/SQL程序由可以嵌套的块组成,并且块结构如下所示:
DECLARE -- it contains declaration statements BEGIN -- It contains executable statements EXCEPTIONS -- It contains exception handling statements END;
示例
在PL/SQL中,单行注释以双连字符(-)开头,多行注释以斜杠-星号(/*)开头,并以星号-斜杠(*/)结尾
--Declaration Block
DECLARE
-- Declaration of string for nhooo
St VARCHAR2(100) := 'nhooo';
-- 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输出结果
如果我们运行上面的程序,那么它将生成以下输出
nhooo tutorialspoin tutorialspoi tutorialspo tutorialsp tutorials tutorial tutoria tutori tutor tuto tut tu t