0% found this document useful (0 votes)
219 views

PL/SQL: Disadvantages of SQL

The document discusses the differences between SQL and PL/SQL, defining PL/SQL as a programming language that allows high-level instructions to accomplish tasks. It notes that PL/SQL adds procedural language features to SQL. The key aspects covered are: 1. PL/SQL programs have a predefined block structure of declare, executable, and exception sections. 2. Variables must be declared in the declare section before being used. 3. PL/SQL supports features like conditional execution and looping that SQL does not.

Uploaded by

Chaitanya Adapa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
219 views

PL/SQL: Disadvantages of SQL

The document discusses the differences between SQL and PL/SQL, defining PL/SQL as a programming language that allows high-level instructions to accomplish tasks. It notes that PL/SQL adds procedural language features to SQL. The key aspects covered are: 1. PL/SQL programs have a predefined block structure of declare, executable, and exception sections. 2. Variables must be declared in the declare section before being used. 3. PL/SQL supports features like conditional execution and looping that SQL does not.

Uploaded by

Chaitanya Adapa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PL/SQL: Disadvantages of SQL: 1. We can't execute multiple statements at a time. 2. We can't write programming language features on SQL. 3.

Inability to Implement Recursive Processing. 4. Incompatibility and Complexity 5. Limited Functionality

a. Conditional Execution If a=10 then select * from emp where deptno = 10; else select * from emp where deptno=20; endif; b. Loopings for i in 1.....10 loop update emp; end loop; Definition: It is a Programming language that allows us to write high level computer instructions to accomplish a given task. PL/SQL stands for Procedural Language extension for SQL. A program that is written in PL/SQL has a predefined structure. PL/SQL = SQL + Procedural language features. Note: All SQL commands can be used in PL/SQL. DML, TCL can be directly used. DDL, DCL can be used indirectly with a concept of dynamic SQL. Oracle software contains two engines: 1. SQL engine 2. PL/SQL engine PL/SQL -- Block Structured Programming language

C -- Object based C++ -- OOP Java -- OOPS PL/SQL is a block structured language Each PL/SQL program is divided into different blocks/different sections.

Single PL/SQL block divided: 1. Declare section -- We will be declaring all necessary variables for your program execution. 2. Executable section -- We will be writing all PL/SQL coding in this section. 3. Exceptional section (Error handling) -- If we get any error in program (Block) we will handle in this section. 4. End; PL/SQL Program Example: DECLARE N1 Number; -- Indentifying the name of the memory location that will hold first number. N2 Number; -- Indentifying the name of the memory location that will hold Second number. Result Number; -- Indentifying the name of the memory location that will hold result of addition. BEGIN N1:=4; -- Storing the value 4 as the value of the first number identified by N1. N2:=3; -- Storing the value 3 as the value of the first number identified by N2. Result: =N1+N2; -- Adding the values of N1 and N2 and storing it in result. DBMS_OUTPUT.PUT_LINE (RESULT); -- Displaying the value of Result on Screen. END;

Structure of PL/SQL Block: DECLARE -- this is optional section Here we will declare all variables. It is optional because not all programs will have variables to declare. BEGIN -- Mandatory We will write all PL/SQL coding in this section. EXCEPTION -- this is optional section

All error handling is done in this section. END; PL/SQL blocks are divided into two types: 1. Anonymous PL/SQL blocks -- PL/SQL block without any name is called as Anonymous PL/SQL block -- These blocks will not store in database permanently. 2. Named PL/SQL block -- A PL/SQL block with a name associated to it. -- Stores in database permanently until we drop it. -- We can execute these blocks any number of times from anywhere. EX of Named PL/SQL blocks: Procedures Functions Packages Triggers Note: Every PL/SQL program follows this block structures. Nesting of PL/SQL blocks is possible. I.e. Block inside a block EX: DECLARE BEGIN DECLARE BEGIN DECLARE BEGIN END; EXECEPTION END; EXCEPTION END; Note: Data available in child block can be available in Parent block but its not true for vise versa. Note: 1. -- is for single line comment

2. /* multi line comment. */ 3. || for concatenating two variables. a: = 'SAMPLE' b := 'WELCOME' c := a||b; -- SAMPLEWELCOME 4.:= is for assignment operator

Simple PL/SQL block: set serveroutput on -- this is enabling buffer output declare begin dbms_output.put_line('welcome to PL/SQL') -- is for displaying messages. end; If we don't have any variables to declare, then DECLARE doesnt need to be mentioned. But it is a good practice to mention it every time. PL/SQL Variables: Variable is a place holds that can stores value during program execution. All PL/SQL variables should be declared before using. We can declare all variables in DECLARE section of PL/SQL block. Declaring a variable: <variablename> [constant] datatype(size) [default value] [not null := value]; 1. Every variable should have a data type. 2. Default value of a variable is NULL. 3. If we declare a variable as a constant, that means we cannot change value of that variable and compulsory we have to give some value to it during declaration. 4. Default value clause specifies default value what we are giving to that variable. 5. If we declare a variable as NOT NULL i.e. we have to give a value to it during declaration and we can't assign NULL to it during program execution. All SQL data types are valid in PL/SQL. NUMBER DATE CHAR VARCHAR2 LOB,CLOB,BLOB

TIMESTAMP Examples of variable declaration: salary number(5); -- it is number variable of size 5 i.e 0 to 99999 deptno constant varchar2(10); -- this is wrong deptno constant varchar2(10):='sample'; -- this is Right a number(3) default 10; declaring a variable with number type and 10 as default number a number(3) :=10; same as above b varchar2(10) not null :='HR'; Note: ALL SQL Data types are valid in PL/SQL.

You might also like