0% found this document useful (0 votes)
57 views7 pages

03b - PL-SQL Fundamentals I - PL-SQL Blocks

This document discusses the structure and syntax rules of PL/SQL blocks. A PL/SQL block contains optional sections like DECLARE and EXCEPTION, but requires a BEGIN section to mark the start and an END section to mark the end. Within a block, comments can be added with either single line "--" or multi-line "/*" and "*/" markers. Individual PL/SQL statements must end with a semicolon, while section labels do not.

Uploaded by

aditya chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views7 pages

03b - PL-SQL Fundamentals I - PL-SQL Blocks

This document discusses the structure and syntax rules of PL/SQL blocks. A PL/SQL block contains optional sections like DECLARE and EXCEPTION, but requires a BEGIN section to mark the start and an END section to mark the end. Within a block, comments can be added with either single line "--" or multi-line "/*" and "*/" markers. Individual PL/SQL statements must end with a semicolon, while section labels do not.

Uploaded by

aditya chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Structure of PL/SQL Block

• PL/SQL instructions are contained within units


known as blocks.
• Some blocks are optional.
Section Require Description
d
DECLARE Declares internal program objects,
such as variables.
BEGIN  Marks the beginning of the program
logic.
Program  This is the actual PL/SQL and SQL
Logic statements.
EXCEPTION Marks the beginning of exception
logic.
END  Marks the end of the program logic.
Oracle 11g PL/SQL Fundamentals I
Language Syntax Rules
• Commenting Code
• Like any programming language, you need to
be able to comment your code.
• In Line comment markers ‘- -’
BEGIN
-- Populate a table with 100 rows of test data.
FOR I IN 1..1000 LOOP
-- Include SQL DML statement
INSERT INTO employee (ssn, name)
VALUES (900000000 + I, ‘John Doe’);

Oracle 11g PL/SQL Fundamentals I


Language Syntax Rules
• Multi Line comment markers consist of
• beginning marker (/*)
• end marker (*/)

/*
Block comment outlined by the begin and end marks
*/
BEGIN
-- Populate a table with 100 rows of test data.
FOR I IN 1..1000 LOOP
INSERT INTO employee (ssn, name)
VALUES (900000000 + I, ‘John Doe’);

Oracle 11g PL/SQL Fundamentals I


Language Syntax Rules
• When writing PL/SQL code, remember the
following:
• Only one PL/SQL statement per line
• All execution statement must be terminated
with a semi-colon (;)
BEGIN
FOR I IN 1..1000 LOOP
INSERT INTO employee (ssn, name)
VALUES (900000000 + I, ‘John Doe’);
END LOOP;

Oracle 11g PL/SQL Fundamentals I


Language Syntax Rules
• Statements that simply label a portion of
PL/SQL code are not terminated with the
semi-colon.
BEGIN
FOR I IN 1..1000 LOOP
INSERT INTO employee (ssn, name)
VALUES (900000000 + I, ‘John Doe’);
END LOOP;

Oracle 11g PL/SQL Fundamentals I


Language Syntax Rules Overview
DECLARE This is optional,
but kept for
BEGIN completeness
This is a FOR I IN 1..1000 LOOP
standard
SQL statementINSERT INTO employee (ssn, name)
VALUES (900000000 + I, ‘John Doe’);
within PL/SQL
END LOOP; The COMMIT
Loop
COMMIT;
statement
EXCEPTION
executes after
WHEN OTHERS THEN the loop
In the event of an
ROLLBACK; error, all prior
execution is rolled
END;
/ back

Oracle 11g PL/SQL Fundamentals I


See it in action

Oracle 11g PL/SQL Fundamentals I

You might also like