Академический Документы
Профессиональный Документы
Культура Документы
What is Sub-Program?
A sub-program is a PL/SQL block which will be invoked by taking parameters.
There are two types of Sub-Programs
(i) Procedure
(ii) Function
Implicit Explicit
1. It is defined by Oracle and used by 1. It is defined by User and used by User.
Oracle and User.
2. In this there is no need to open or 2. In this we have to open and close the
close the Cursor. Cursor
When Cursor selects the records at Declaration [or] Open [or] Fetch?
At Open state.
Ex:
1. Cursor with Inline view
What is Procedure?
(i) It is mainly used for data processing.
(ii) It is a named PL/SQL.
(iii) It is a database object (user_source).
(iv) The procedure in oracle known as ‘stored procedure’.
(v) When we invoke procedure, every time not required to compile.
(vi) Procedures can be re-used many times.
(vii) It accepts parameters.
(viii) It may or may not return value depending on how we write procedure.
If I have an Execute Privilege on a procedure in other user schema, can I execute this procedure
even I do not have privilege on the tables which are used in the Procedure?
Yes
What is the difference between Cursor declared in a Procedure and Cursor declared in a
Package?
The Cursor declared in a Procedure will be accessed only with in that procedure where as the Cursor
declared in a Package can be accessed across the Package.
What is Function?
(i) It is used for Calculation.
(ii) It is a named PL/SQL block.
(iii) It is a database object (user_source).
(iv) It accepts parameters like IN, OUT, IN OUT.
(v) It always returns a value.
(vi) We can invoke Function in a select statement also with some restriction.
(vii) We cannot invoke function in a select statement if function is defined with OUT (or) IN
OUT parameter (or) DML operations.
Can we have two Functions with the same name in a PL/SQL block?
Yes, it is possible in a Package.
Can 2 Functions have same name and Input parameters, but differ only by return value data
type?
No, it is not possible.
Procedure Function
1. It is used for Data processing. 1. It is used for Calculation purpose.
2. It may or may not return a value 2. In this it will return a value.
based on the program how we define.
3. It cannot be invoked in a Select 3. Function can be invoked in a Select
statement. statement.
What is a Package?
It is mainly used to hide the business logic.
It is a logical container which groups related Objects (procedures, functions, variables) together for a
common business function.
Using Package we can develop OOPs concepts by overloading Procedures and Functions.
What is the difference between Table Level and Row Level triggers?
Table Level triggers executes once for each table based on Transaction where as Row Level triggers
executes once for each row.
What is Pragma?
It is a set of rules to compiler to do specific tasks at compilation time.
What is Autonomous?
It is used to make local Transactions Autonomous so that it will not effect to any other transactions.
What is Ref-Cursor?
It is a Dynamic Cursor which is used to change the action of Cursor query at run-time.
It can access more than one memory area at run-time.
It works like Pointer in C-Language.
What is Exception?
(i) Any error raised in exception area is known as Exception.
(ii) If exception is not handled in exception area, the whole pl/sql block terminated with
failure and all transactions will be rollback.
Example:
declare
vsal number(7,2);
begin
select sal into vsal from emp where empno=&pno;
dbms_output.put_line(vsal);
exception
when no_data_found then
dbms_output.put_line("Invalid number...');
end;
Example:
declare
vsal number(7,2);
exp_sal exception;
vempno number(4);
begin
vempno:=&pno;
select sal into vsal from emp where empno=vempno;
if vsal>2000 then
raise exp_sal;
else
update emp set comm=sal*.20 where empno=vempno;
dbms_output.put_line(vempno||' '||'is updated');
end if;
exception
when no_data_found then
dbms_output.put_line('Invalid data...');
when exp_sal then
dbms_output.put_line('salary:'||vsal||' '||'is more for update...');
end;
How to use Non Pre-defined Exception?
(i) It is defined by User
(ii) Raised by Oracle
(iii) Handled by User
Example:
declare
vempno number(4);
exp_integrity exception;
pragma exception_init(exp_integrity,-01422);
begin
select empno into vempno from emp where deptno=30;
dbms_output.put_line(vempno);
exception
when exp_integrity then
dbms_output.put_line('stmt returns More than one row...');
end;
What happens when commit is given in executable section when an error occurs?
It Rollback the transactions
What is Raise_Application_Error?
It is Oracle defined Procedure.
It is a procedure which is used to stop the execution of the process and displays the user message.
The error number must be in the range of -20,000 to -20,999
Example:
declare
vsal number(7,2);
vempno number(4);
begin
vempno:=&no;
select sal into vsal from emp where empno=vempno;
if vsal>2000 then
raise_application_error(-20001,'more salary for update');
else
update emp set comm=sal*.20 where empno=vempno;
dbms_output.put_line(vempno||' '||'comm is updated...');
end if;
exception
when no_data_found then
raise_application_error(-20001,'more salary for update');
end;
What is SQL*Loader?
It is used to transfer data from Legacy System data to Oracle database.
Suppose there are two columns in a table, if one column is null then how to insert?
Using ‘Trailing Nullcols’
What is UTL_FILE?
(i) It is a database Package.
(ii) It is used for loading data from legacy system to Oracle database.
(iii) It is also used for creating data files of Oracle database.
(iv) The Data file must be stored in a particular
(v) It supports validations
2. It can be used for more than 2. It can be used for one file at a time.
one file at a time.