PL SQL
PL SQL
PL/SQL Variables
A variable is a meaningful name which facilitates a programmer to store
data temporarily during the execution of code. It helps you to manipulate
data in PL/SQL programs. It is nothing except a name given to a storage
area. Each variable in the PL/SQL has a specific data type which defines
the size and layout of the variable's memory.
Number
SQL> Set Serveroutput On;
H
SQL> Declare
2 a Number :=30;
3 b Number :=20;
C
4 c Number;
5 Begin
6 c:=a+b;
TE
7 Dbms_Output.Put_Line('The c value is : '||c);
8 End;
9 /
The c value is : 50
Float
I-
3 b Float :=20.23;
4 c Float;
5 Begin
6 c:=a+b;
7 Dbms_Output.Put_Line('The c value is : '||c);
8 End;
9 /
The c value is : 50.23
PL/SQL 1
HI - TECH COMPUTERS
Char
SQL> Declare
2 a Varchar2(2) :='H';
3 Begin
4 Dbms_Output.Put_Line('The a value is : '||a);
5 End;
6 /
H
The a value is : H
C
String
SQL> Declare
TE
2 a Varchar2(10) :='HI-TECH';
3 Begin
4 Dbms_Output.Put_Line('The a value is : '||a);
5 End;
6 /
The a value is : HI-TECH
User Input
SQL> Declare
2 a Number;
H
3 b Number;
4 c Number;
5 Begin
6 a:=&a;
7 b:=&b;
8 c:=a+b;
9 Dbms_Output.Put_Line('The c value is : '||c);
10 End;
PL/SQL 2
HI - TECH COMPUTERS
11 /
H
new 7: b:=6;
The c value is : 11
C
PL/SQL procedure successfully completed.
TE
PL/SQL If
PL/SQL supports the programming language features like conditional
statements and iterative statements. Its programming constructs are
similar to how you use in programming languages like Java and C++.
1. IF condition
2. THEN
H
This syntax is used when you want to execute statements only when
condition is TRUE.
1. IF condition
2. THEN
PL/SQL 3
HI - TECH COMPUTERS
3. {...statements to execute when condition is TRUE...}
4. ELSE
5. {...statements to execute when condition is FALSE...}
6. END IF;
This syntax is used when you want to execute one set of statements when
condition is TRUE or a different set of statements when condition is
FALSE.
H
1. IF condition1
2. THEN
3. {...statements to execute when condition1 is TRUE...}
C
4. ELSIF condition2
5. THEN
6. {...statements to execute when condition2 is TRUE...}
TE
7. END IF;
This syntax is used when you want to execute one set of statements when
condition1 is TRUE or a different set of statements when condition2 is
TRUE.
1. IF condition1
I-
2. THEN
3. {...statements to execute when condition1 is TRUE...}
4. ELSIF condition2
5. THEN
H
It is the most advance syntax and used if you want to execute one set of
statements when condition1 is TRUE, a different set of statement when
PL/SQL 4
HI - TECH COMPUTERS
condition2 is TRUE or a different set of statements when both the
condition1 and condition2 are FALSE.
H
SQL> Set Serveroutput On;
SQL> Declare
2 a Number(3):=500;
C
3 Begin
4 If(a<20)
5 Then
6 Dbms_Output.Put_Line('a is Less Then 20');
TE
7 Else
8 Dbms_Output.Put_Line('a is Not Less Then 20');
9 End If;
10 Dbms_Output.Put_Line('Value of a is: '||a);
11 End;
12 /
a is Not Less Then 20
Value of a is: 500
PL/SQL 5
HI - TECH COMPUTERS
PL/SQL Case Statement
The PL/SQL CASE statement facilitates you to execute a sequence of
satatements based on a selector. A selector can be anything such as
variable, function or an expression that the CASE statement checks to a
boolean value.
The CASE statement works like the IF statement, only using the keyword
WHEN. A CASE statement is evaluated from top to bottom. If it get the
condition TRUE, then the corresponding THEN calause is executed and the
execution goes to the END CASE clause.
H
1. CASE [ expression ]
2. WHEN condition_1 THEN result_1
C
3. WHEN condition_2 THEN result_2
4. ...
5. WHEN condition_n THEN result_n
TE
6. ELSE result
7. END
3 Begin
4 Case Grade
5 When 'A'
6 Then
7 Dbms_Output.Put_Line('Excellent');
8 When 'B'
H
9 Then
10 Dbms_Output.Put_Line('Very Good');
11 When 'C'
12 Then
13 Dbms_Output.Put_Line('Good');
14 When 'D'
15 Then
16 Dbms_Output.Put_Line('Average');
17 When 'F'
18 Then
19 Dbms_Output.Put_Line('Passed');
PL/SQL 6
HI - TECH COMPUTERS
20 Else
21 Dbms_Output.Put_Line('Fail');
22 End Case;
23 End;
24 /
Excellent
H
C
TE
I-
H
PL/SQL 7
HI - TECH COMPUTERS
PL/SQL Loop
The PL/SQL loops are used to repeat the execution of one or more
statements for specified number of times. These are also known as
iterative control statements.
1. LOOP
2. Sequence of statements;
3. END LOOP;
H
Types of PL/SQL Loops
There are 4 types of PL/SQL Loops.
C
Basic Loop / Exit Loop
While Loop
TE
For Loop
1. LOOP
2. Sequence of statements;
H
3. END LOOP;
1. LOOP
2. statements;
3. EXIT;
4. {or EXIT WHEN condition;}
PL/SQL 8
HI - TECH COMPUTERS
5. END LOOP;
1. DECLARE
2. i NUMBER := 1;
3. BEGIN
4. LOOP
H
5. EXIT WHEN i>10;
6. DBMS_OUTPUT.PUT_LINE(i);
7. i := i+1;
C
8. END LOOP;
9. END;
TE
Note: You must follow these steps while using PL/SQL Exit Loop.
● You should use the EXIT WHEN statement to exit from the Loop.
Otherwise the EXIT statement without WHEN condition, the statements
in the Loop is executed only once.
I-
2. VAR1 NUMBER;
3. VAR2 NUMBER;
4. BEGIN
5. VAR1:=100;
6. VAR2:=1;
7. LOOP
8. DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
PL/SQL 9
HI - TECH COMPUTERS
9. IF (VAR2=10) THEN
10. EXIT;
11. END IF;
12. VAR2:=VAR2+1;
13. END LOOP;
14. END;
H
C
TE
I-
H
PL/SQL 10
HI - TECH COMPUTERS
PL/SQL While Loop
PL/SQL while loop is used when a set of statements has to be executed as
long as a condition is true, the While loop is used. The condition is
decided at the beginning of each iteration and continues until the
condition becomes false.
1. WHILE <condition>
2. LOOP statements;
3. END LOOP;
H
Example of PL/SQL While Loop
C
Let's see a simple example of PL/SQL WHILE loop.
1. DECLARE
2. i INTEGER := 1;
TE
3. BEGIN
4. WHILE i <= 10 LOOP
5. DBMS_OUTPUT.PUT_LINE(i);
6. i := i+1;
7. END LOOP;
8. END;
I-
Note: You must follow these steps while using PL/SQL WHILE Loop.
H
● You can use EXIT WHEN statements and EXIT statements in While loop
but it is not done often.
PL/SQL 11
HI - TECH COMPUTERS
H
4. BEGIN
5. VAR1:=200;
6. VAR2:=1;
C
7. WHILE (VAR2<=10)
8. LOOP
9. DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
TE
10. VAR2:=VAR2+1;
11. END LOOP;
12. END;
I-
H
PL/SQL 12
HI - TECH COMPUTERS
PL/SQL FOR Loop
PL/SQL for loop is used when when you want to execute a set of statements
for a predetermined number of times. The loop is iterated between the
start and end integer values. The counter is always incremented by 1 and
once the counter reaches the value of end integer, the loop ends.
H
● initial_value : Start integer value
C
TE
Let's see a simple example of PL/SQL FOR loop.
1. BEGIN
2. FOR k IN 1..10 LOOP
3. -- note that k was not declared
4. DBMS_OUTPUT.PUT_LINE(k);
5. END LOOP;
I-
6. END;
Note: You must follow these steps while using PL/SQL WHILE Loop.
● You can use EXIT WHEN statements and EXIT statements in FOR Loops but
it is not done often.
PL/SQL 13
HI - TECH COMPUTERS
H
C
TE
I-
H
PL/SQL 14
HI - TECH COMPUTERS
PL/SQL For Loop Example 2
1. DECLARE
2. VAR1 NUMBER;
3. BEGIN
4. VAR1:=10;
5. FOR VAR2 IN 1..10
6. LOOP
7. DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
H
8. END LOOP;
9. END;
C
PL/SQL For Loop REVERSE Example 3
Let's see an example of PL/SQL for loop where we are using REVERSE
keyword.
TE
1. DECLARE
2. VAR1 NUMBER;
3. BEGIN
4. VAR1:=10;
5. FOR VAR2 IN REVERSE 1..10
6. LOOP
I-
7. DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
8. END LOOP;
9. END;
H
PL/SQL 15
HI - TECH COMPUTERS
PL/SQL Continue Statement
The continue statement is used to exit the loop from the reminder if its
body either conditionally or unconditionally and forces the next iteration
of the loop to take place, skipping any codes in between.
H
SQL> BEGIN
C
2 FOR i IN 1 .. 5 LOOP
3 IF i = 3 THEN
TE
4 CONTINUE;
5 END IF;
7 END LOOP;
8 END;
9 /
I-
Iteration # 1
Iteration # 2
Iteration # 4
H
Iteration # 5
PL/SQL 16
HI - TECH COMPUTERS
PL/SQL GOTO Statement
In PL/SQL, GOTO statement makes you able to get an unconditional jump from
the GOTO to a specific executable statement label in the same subprogram
of the PL/SQL block.
Syntax:
1. GOTO label_name;
H
Here the label declaration which contains the label_name encapsulated
within the << >> symbol and must be followed by at least one statement to
execute.
C
1. GOTO label_name;
2. ..
TE
3. ..
4. <<label_name>>
5. Statement;
1. DECLARE
2. a number(2) := 30;
3. BEGIN
H
4. <<loopstart>>
5. -- while loop execution
6. WHILE a < 50 LOOP
7. dbms_output.put_line ('value of a: ' || a);
8. a := a + 1;
9. IF a = 35 THEN
10. a := a + 1;
11. GOTO loopstart;
PL/SQL 17
HI - TECH COMPUTERS
12. END IF;
13. END LOOP;
14. END;
15. /
H
C
TE
I-
H
PL/SQL 18
HI - TECH COMPUTERS
Oracle Procedures
A procedure is a group of PL/SQL statements that can be called by name.
The call specification (sometimes called call spec) specifies a java
method or a third-generation language routine so that it can be called
from SQL and PL/SQL.
Create Procedure
Syntax
H
2. [ (parameter [,parameter]) ]
3. AS
C
4. [declaration_section]
5. BEGIN
6. executable_section
TE
7. [EXCEPTION
8. exception_section]
9. END [procedure_name];
Following are the three types of procedures that must be defined to create
a procedure.
Procedure created.
PL/SQL 19
HI - TECH COMPUTERS
SUM
----------
12
H
PL/SQL procedure successfully completed.
C
SUM
----------
30
TE
SQL> Create Table Yes
2 (
3 Id Number(10),
4 Name Varchar2(10)
5 );
Table created.
I-
1 row created.
H
1 row created.
ID NAME
---------- ----------
1 Hari
2 Ram
PL/SQL 20
HI - TECH COMPUTERS
Procedure created.
H
SQL> Select * From Yes;
ID NAME
---------- ----------
C
1 Hari
2 Ram
3 Suma
TE
I-
H
PL/SQL 21
HI - TECH COMPUTERS
Oracle Function
A function is a subprogram that is used to return a single value. You must
declare and define a function before invoking it. It can be declared and
defined at the same time or can be declared first and defined later in the
same block.
CREATE function in Oracle
Syntax
CREATE [OR REPLACE] FUNCTION function_name
[ (parameter [,parameter]) ]
RETURN return_datatype
IS | AS
[declaration_section]
H
BEGIN
executable_section
[EXCEPTION
exception_section]
C
END [function_name];
5 Tel Number(10),
6 Eng Number(10)
7 );
Table created.
H
1 row created.
1 row created.
H
7 Return (Mark1+Mark2)/2;
8 End;
9 /
C
Function created.
PL/SQL 23
HI - TECH COMPUTERS
PL/SQL Cursor
When an SQL statement is processed, Oracle creates a memory area known as
context area. A cursor is a pointer to this context area. It contains all
information needed for processing the statement. In PL/SQL, the context
area is controlled by Cursor. A cursor contains information on a select
statement and the rows of data accessed by it.
H
● Implicit Cursors
● Explicit Cursors
C
1) PL/SQL Implicit Cursors
The implicit cursors are automatically generated by Oracle while an SQL
statement is executed, if you don't use an explicit cursor for the
TE
statement.
These are created by default to process the statements when DML statements
like INSERT, UPDATE, DELETE etc. are executed.
For example: When you execute the SQL statements like INSERT, UPDATE,
I-
DELETE then the cursor attributes tell whether any rows are affected and
how many have been affected. If you run a SELECT INTO statement in PL/SQL
block, the implicit cursor attribute can be used to find out whether any
row has been returned by the SELECT statement. It will return an error if
there no data is selected.
H
The following table soecifies the status of the cursor with each of its
attribute.
Attribute Description
PL/SQL 24
HI - TECH COMPUTERS
a SELECT INTO statement returned one or more rows.
Otherwise it returns FALSE.
H
SQL cursor is automatically closed after executing its
associated SQL statements.
C
like INSERT, DELETE, and UPDATE or returned by a SELECT
INTO statement.
TE
SQL> Create Table Curser
2 (
3 Id Number(5),
4 Name Varchar2(10),
5 Age Number(5),
6 Address Varchar2(10),
7 salary Number(5)
I-
8 );
Table created.
1 row created.
1 row created.
PL/SQL 25
HI - TECH COMPUTERS
1 row created.
1 row created.
1 row created.
H
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Ramesh 23 Puttur 20000
C
2 Suresh 22 Puttur 22000
3 Mahesh 24 Nagari 24000
4 Chandra 25 Chittoor 26000
5 Alex 23 Chittoor 28000
TE
SQL> Set Serveroutput on;
SQL> Declare
2 total_rows number(2);
3 Begin
4 Update Curser
5 Set salary = salary+5000;
6 if sql%notfound Then
7 dbms_output.put_line('No Curser Update');
8 elsif sql%found Then
I-
9 total_rows:=sql%rowcount;
10 dbms_output.put_line(total_rows||'Curser Updated');
11 end if;
12 end;
13 /
H
5Curser Updated
H
C
TE
I-
H
PL/SQL 27
HI - TECH COMPUTERS
2) PL/SQL Explicit Cursors
The Explicit cursors are defined by the programmers to gain more control
over the context area. These cursors should be defined in the declaration
section of the PL/SQL block. It is created on a SELECT statement which
returns more than one row.
H
1. CURSOR cursor_name IS select_statement;;
Steps:
C
You must follow these steps while working with an explicit cursor.
It defines the cursor with a name and the associated SELECT statement.
1. CURSOR name IS
H
2. SELECT statement;
1. OPEN cursor_name;
PL/SQL 28
HI - TECH COMPUTERS
3) Fetch the cursor:
It is used to access one row at a time. You can fetch rows from the
above-opened cursor as follows:
H
It is used to release the allocated memory. The following syntax is used
to close the above-opened cursors.
C
1. Close cursor_name;
TE
SQL> Create Table Curser
2 (
3 Id Number(5),
4 Name Varchar2(10),
5 Age Number(5),
6 Address Varchar2(10),
I-
7 Salary Number(5)
8 );
H
Table created.
2 (1,'Ramesh',23,'Puttur',25000);
1 row created.
PL/SQL 29
HI - TECH COMPUTERS
2 (2,'Suresh',22,'Puttur',27000);
1 row created.
H
2 (3,'Mahesh',24,'Nagari',29000);
1 row created.
C
TE
2 (4,'Chandra',25,'Chittoor',31000);
1 row created.
2 (5,'Alex',23,'Chittoor',33000);
1 row created.
H
SQL> DECLARE
H
2 c_id [Link]%type;
3 c_name [Link]%type;
4 c_addr [Link]%type;
C
5 Cursor c_Curser is
8 Open c_Curser;
9 Loop
12 Dbms_Output.put_Line(c_id||''||c_name||''||c_addr);
13 End Loop;
14 Close c_Curser;
H
15 End;
16 /
1RameshPuttur
2SureshPuttur
3MaheshNagari
4ChandraChittoor
5AlexChittoor
PL/SQL 31
HI - TECH COMPUTERS
H
C
TE
I-
H
PL/SQL 32
HI - TECH COMPUTERS
What is Exception
H
● System-defined Exceptions
● User-defined Exceptions
C
TE
Following is a general syntax for exception handling:
1. DECLARE
2. <declarations section>
3. BEGIN
4. <executable command(s)>
5. EXCEPTION
I-
10. exception2-handling-statements
11. WHEN exception3 THEN
12. exception3-handling-statements
13. ........
14. WHEN others THEN
15. exception3-handling-statements
16. END;
PL/SQL 33
HI - TECH COMPUTERS
H
1 Ramesh 23 Puttur 25000
C
3 Mahesh 24 Nagari 29000
1. c_id [Link]%type := 8;
2. c_name [Link]%type;
3. c_addr [Link]%type;
4. BEGIN
5. SELECT name, address INTO c_name, c_addr
I-
6. FROM customers
7. WHERE id = c_id;
8. DBMS_OUTPUT.PUT_LINE ('Name: '|| c_name);
H
PL/SQL 34
HI - TECH COMPUTERS
After the execution of above code at SQL Prompt, it produces the following
result:
No such customer!
H
1. DECLARE
2. c_id [Link]%type := 5;
C
TE
3. c_name [Link]%type;
4. c_addr [Link]%type;
5. BEGIN
6. SELECT name, address INTO c_name, c_addr
7. FROM customers
8. WHERE id = c_id;
I-
After the execution of above code at SQL prompt, you will get the
following result:
PL/SQL 35
HI - TECH COMPUTERS
H
C
TE
I-
H
PL/SQL 36
HI - TECH COMPUTERS
H
Exception Oracle SQL Code Description
Error
C
ACCESS_INTO_NULL 06530 -6530 It is raised when a NULL
object is automatically
TE
assigned a value.
no else clause.
LL attempts to apply
collection methods other
than exists to an
uninitialized nested table
or varray, or the program
attempts to assign values
to the elements of an
PL/SQL 37
HI - TECH COMPUTERS
uninitialized nested table
or varray.
H
INVALID_CURSOR 01001 -1001 It is raised when attempts
are made to make a cursor
C
operation that is not
allowed, such as closing an
unopened cursor.
TE
INVALID_NUMBER 01722 -1722 It is raised when the
conversion of a character
string into a number fails
because the string does not
represent a valid number.
I-
PL/SQL 38
HI - TECH COMPUTERS
H
ROWTYPE_MISMATCH 06504 -6504 It is raised when a cursor
fetches value in a variable
C
having incompatible data
type.
TE
SELF_IS_NULL 30625 -30625 It is raised when a member
method is invoked, but the
instance of the object type
was not initialized.
I-
PL/SQL 39
HI - TECH COMPUTERS
H
attempt is made to divide a
number by zero.
C
TE
I-
H
PL/SQL 40
HI - TECH COMPUTERS
Oracle Trigger
In Oracle, you can define procedures that are implicitly executed when an
INSERT, UPDATE or DELETE statement is issued against the associated table.
These procedures are called database triggers.
There are six CREATE TRIGGER statements according to their firing points.
H
● BEFORE UPDATE TRIGGER
C
Firing Point: AFTER
USER is "SYS"
I-
User created.
Grant succeeded.
Grant succeeded.
Grant succeeded.
H
USER is "SYS"
C
Enter password:
Connected.
TE
SQL> Show User;
USER is "C##BOOK"
2 (
I-
3 F_Id Number(5),
4 F_Name Varchar2(10),
5 F_Unit_Price Number(5)
H
6 );
Table created.
2 (
3 P_Id Number(5),
PL/SQL 42
HI - TECH COMPUTERS
4 P_Name Varchar2(10),
5 P_Unit_Price Number(5)
6 );
Table created.
H
2 (101,'CRT',1000);
1 row created.
C
TE
F_ID F_NAME F_UNIT_PRICE
no rows selected
H
3 Begin
5 End;
PL/SQL 43
HI - TECH COMPUTERS
6 /
Trigger created.
H
---------- ---------- ------------
C
SQL> Select * From Price;
TE
no rows selected
1 row updated.
PL/SQL 44
HI - TECH COMPUTERS
P_ID P_NAME P_UNIT_PRICE
H
C
TE
I-
H
PL/SQL 45
HI - TECH COMPUTERS
PL/SQL Interview Questions
PL/SQL is an advance version of SQL. There are given top list of PL/SQL
interview questions with answer.
1) What is PL/SQL?
H
2) What is the purpose of using PL/SQL?
C
PL/SQL is an extension of SQL. While SQL is non-procedural, PL/SQL is a
procedural language designed by Oracle. It is invented to overcome the
limitations of SQL.
TE
3) What are the most important characteristics of PL/SQL?
Objects of type tables are called PL/SQL tables that are modeled as
database table. We can also say that PL/SQL tables are a way to providing
arrays. Arrays are like temporary tables in memory that are processed very
PL/SQL 46
HI - TECH COMPUTERS
quickly. PL/SQL tables are used to move bulk data. They simplifies moving
collections of data.
H
2. Composite datatypes Example are RECORD, TABLE etc.
C
6) What is the basic structure of PL/SQL?
PL/SQL uses BLOCK structure as its basic structure. Each PL/SQL program
TE
consists of SQL and PL/SQL statement which form a PL/SQL block.
Procedure: A procedure does not have a return type and should not return
any value but it can have a return statement that simply stops its
execution and returns to the caller. A procedure is used to return
multiple values otherwise it is generally similar to a function.
PL/SQL 47
HI - TECH COMPUTERS
Package: A package is schema object which groups logically related PL/SQL
types , items and subprograms. You can also say that it is a group of
functions, procedure, variables and record type statement. It provides
modularity, due to this facility it aids application development. It is
used to hide information from unauthorized users.
H
exceptions: pre_defined exception and user_defined exception.
C
9) How to write a single statement that concatenates the
words ?Hello? and ?World? and assign it in a variable named
Greeting?
TE
Greeting := 'Hello' || 'World';
No. PL/SQL doesn't support the data definition commands like CREATE.
I-
PL/SQL 48
HI - TECH COMPUTERS
Whenever an Error occurs Exception arises. Error is a bug whereas
exception is a warning or error condition.
H
14) What are PL/SQL exceptions? Tell me any three.
1. Too_many_rows
2. No_Data_Found
C
3. Value_error
4. Zero_error etc.
TE
15) How do you declare a user-defined exception?
You can declare the User defined exceptions under the DECLARE section,
with the keyword EXCEPTION.
Syntax:
I-
1. <exception_name> EXCEPTION;
● DUP_VAL_ON_INDEX
● ZERO_DIVIDE
● NO_DATA_FOUND
● TOO_MANY_ROWS
PL/SQL 49
HI - TECH COMPUTERS
● CURSOR_ALREADY_OPEN
● INVALID_NUMBER
● INVALID_CURSOR
● PROGRAM_ERROR
● TIMEOUT _ON_RESOURCE
● STORAGE_ERROR
● LOGON_DENIED
H
● VALUE_ERROR
● etc.
C
TE
A trigger is a PL/SQL program which is stored in the database. It is
executed immediately before or after the execution of INSERT, UPDATE, and
DELETE commands.
12 triggers.
H
PL/SQL 50
HI - TECH COMPUTERS
● AFTER INSERT etc.
H
21) What happens when a trigger is associated to a view?
C
normally enabled.
TE
22) What is the usage of WHEN clause in trigger?
A WHEN clause specifies the condition that must be true for the trigger to
be triggered.
25) what are the two virtual tables available at the time
of database trigger execution?
PL/SQL 51
HI - TECH COMPUTERS
Table columns are referred as THEN.column_name and NOW.column_name.
H
A stored procedure is a sequence of statement or a named PL/SQL block
which performs one or more specific functions. It is similar to a
procedure in other programming languages. It is stored in the database and
C
can be repeatedly executed. It is stored as schema object. It can be
nested, invoked and parameterized.
TE
27) What are the different schemas objects that can be
created using PL/SQL?
● Packages
I-
● Triggers
● Cursors
H
Oracle uses workspaces to execute the SQL commands. When Oracle processes
a SQL command, it opens an area in the memory called Private SQL Area.
This area is identified by the cursor. It allows programmers to name this
area and access it?s information.
PL/SQL 52
HI - TECH COMPUTERS
29) What is the difference between the implicit and
explicit cursors?
H
The cursor attribute SQL%ROWCOUNT will return the number of rows that are
processed by a SQL statement.
C
31) What will you get by the cursor attribute SQL%FOUND?
TE
It returns the Boolean value TRUE if at least one row was processed.
PL/SQL 53
HI - TECH COMPUTERS
Specification part: It specifies the part where the interface to the
application is defined.
H
36) How to execute a stored procedure?
C
There are two way to execute a stored procedure.
1. procedure_name;
I-
PL/SQL 54
HI - TECH COMPUTERS
%FOUND: it checks whether cursor has fetched any row. If yes - TRUE.
H
exception-handling section in a PL/SQL block. For example: SELECT INTO
statement, which does not return any rows.
C
Following conditions are true for the Commit statement:
TE
● Other users can see the data changes made by the transaction.
Mutating table error is occurred when a trigger tries to update a row that
it is currently using. It is fixed by using views or temporary tables.
H
Consistency simply means that each user sees the consistent view of the
data.
Consider an example: there are two users A and B. A transfers money to B's
C
account. Here the changes are updated in A's account (debit) but until it
will be updated to B's account (credit), till then other users can't see
the debit of A's account. After the debit of A and credit of B, one can
TE
see the updates. That?s consistency.
row, but can process only one row at a time. Cursor are required to
process rows individually for queries.
PL/SQL 56
HI - TECH COMPUTERS
2. explicit cursor
H
C
TE
I-
H
PL/SQL 57