用 PL/SQL 列印 tutorialspoint 金字塔
PL/SQL 代表 “SQL 的過程語言擴充套件”。它是程式語言提供的 SQL 和過程特性的混合體。它是 20 世紀 80 年代末由 Oracle Corporation 開發的,作為 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 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
輸出
如果我們執行上面程式,那麼它將生成以下輸出
tutorialspoint tutorialspoin tutorialspoi tutorialspo tutorialsp tutorials tutorial tutoria tutori tutor tuto tut tu t
廣告