PL/SQL Basic Syntax, Block Structure and Anonymous block

PL/SQL is highly structured language and it’s program units are written in block of code, In this tutorial we’ll learn about basic syntax and block structure of PL/SQL

Piece of code that is organized in a proper defined sequence is called a Block. A Block consist of 3 parts

DECLARE

<>

–Declare Variables,Constants, Cursors and all elements

BEGIN

<>

–SQL, PL/SQL Commands

EXCEPTION

<>

–Code to handle exception



END;

So this is the basic structure of a simple PL/SQL block and a block without name is known as Anonymous Block

Anonymous block is the simplest block and it can not be saved in DB so mostly it is used for testing and learning purpose

Let’s write first PL/SQL program/block to print a message in SQL Developer

BEGIN 
DBMS_OUTPUT.PUT_LINE('FIRST PL/SQL PROGRAM');
END;

This anonymous block produces following output

Now see another block in that we’ll declare some variables and perform some calculation

DECLARE 
--Declare Variables
a integer :=10;
b integer :=20;
c integer;
BEGIN
--Perform Calculation
c:=a+b;
dbms_output.put_line('Value of C is- '||c);
END;

and output is

So here we have finished first step towards learning PL/SQL. I am writing these tutorials as my personal notes so there will be more examples than theory part

Cheers :) Happy Learning

您可能感兴趣的

Exposing a column in an Oracle SQL CASE statement I'm trying to modify an SQL select statement to select the inverse value of a column (as in, negative if the value was positive, positive if the value...
Problem Creating a sql Connection String I have an example of a login page that runs off of sql in which I am trying to customize it to my server. I'm running into issues with the sql strin...
Tricks – Copy T SQL Result to Excel Tricks - Copy T SQL Result to Excel Posted on 25 November 2017 Comments Sometimes, some of the silliest of tricks save ...
The difference between these two OpenMP constructi... What is the difference between these two methods for pause / resume threads? I have a multithreaded application which is used to...
How do I add a new table to an item? How can I add an array to an array item? I want each item to have an array assigned to it, in this case with a tags key. But the following doesn...
Ashish Awasthi's Blog责编内容来自:Ashish Awasthi's Blog (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » PL/SQL Basic Syntax, Block Structure and Anonymous block



专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录