Oracle PL-SQL

  Home  Oracle  Oracle PL-SQL


“Oracle PL-SQL Interview Questions and Answers will help you to face a successful Oracle PL-SQL Interview and get hired, here you can learn PL-SQL of Oracle database also and update your knowledge and get preparation for a better job in Oracle PL SQL, So learn PL-SQL with the help of this Oracle PL-SQL Interview Questions with Answers guide”



52 Oracle PL SQL Questions And Answers

1⟩ Explian rowid, rownum?what are the psoducolumns we have?

ROWID - Hexa decimal number each and every row having unique.Used in searching.

ROWNUM - It is a integer number also unique for sorting Normally TOP N Analysys.

Other Psudo Column are

NEXTVAL,CURRVAL Of sequence are some exampls

psudo columns are default columns provided by oracle

 171 views

2⟩ What is difference b/w stored procedures and application procedures, stored function and application function?

Stored procedures are subprogrammes stored in the database and can be called &executee multiple times wherein an application procedure is the one being used for a particular application same is the way for function.

Both can be executed any number of times. Only difference is that stored procedures/ functions are stored in database in complied format while the application procedures/functions are not in precomplied format and at run time has to be compiled.

 173 views

5⟩ How we can create a table in PL/SQL block. insert records into it? is it possible by some procedure or function? please give example?

CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table_name IN VARCHAR2)

AS

l_stmt VARCHAR2(200);

BEGIN

DBMS_OUTPUT.put_line('STARTING ');

l_stmt := 'create table '|| p_table_name || ' as (select * from emp )';

execute IMMEDIATE l_stmt;

DBMS_OUTPUT.put_line('end ');

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.put_line('exception '||SQLERRM || 'message'||sqlcode);

END;

 173 views

7⟩ State the difference between implict and explict cursors?

Implicit Cursor are declared and used by the oracle internally. whereas the explicit cursors are declared and used by the user. more over implicitly cursors are no need to declare oracle creates and process and closes autometically. the explicit cursor should be declared and closed by the user.

Implicit cursors are used for single row query whereas explicit cursor is used for multiple row query

 178 views

8⟩ How to know the last executed procedure?

Execute procedure name (parameter1,parameter2)

Select timestamps, owner, obj_name, action_name from dba_audit_trail;this statement gives last executed time for procedure , function & package.

 143 views

12⟩ What are the components of a PL/SQL block?

A set of related declarations and procedural statements is called block.

DECLARE -- declaration section BEGIN -- executable statements -- main section EXCEPTION -- handling possible exceptions -- occuring in the main section END;

 169 views

14⟩ What are % TYPE and % ROWTYPE? What are the advantages of using these over datatypes?

% TYPE provides the data type of a variable or a database column to that variable.

% ROWTYPE provides the record type that represents a entire row of a table or view or columns selected in the cursor.

The advantages are : I. Need not know about variable's data type

ii. If the database definition of a column in a table changes, the data type of a variable changes accordingly.

 202 views

15⟩ What is difference between % ROWTYPE and TYPE RECORD?

% ROWTYPE is to be used whenever query returns a entire row of a table or view.

TYPE rec RECORD is to be used whenever query returns columns of different

table or views and variables.

E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp ename %type

);

e_rec emp% ROWTYPE

cursor c1 is select empno,deptno from emp;

e_rec c1 %ROWTYPE.

One more point : When we have a variable of typer RECORD we have declare additional variables but with %rowtype, we can only have the fields that are present in the table

 160 views

16⟩ What will the Output for this Coding> Declare Cursor c1 is select * from emp FORUPDATE; Z c1%rowtype; Begin Open C1; Fetch c1 into Z; Commit; Fetch c1 in to Z; end;

By declaring this cursor we can update the table emp through z,means wo not need to write table name for updation,it may be only by "z".

By issuing the TCL like commit or rollback, the cursor will be closed automatically, you cannat fetch again. You will get an error if yuo

 161 views

17⟩ What are the Restrictions on Cursor Variables?

Currently, cursor variables are subject to the following restrictions:You cannot declare cursor variables in a package spec. For example, the following declaration is not allowed:CREATE PACKAGE emp_stuff AS TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; emp_cv EmpCurTyp; -- not allowedEND emp_stuff;You cannot pass cursor variables to a procedure that is called through a database link.If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call.You cannot use comparison operators to test cursor variables for equality, inequality, or nullity.You cannot assign nulls to a cursor variable.Database columns cannot store the values of cursor variables. There is no equivalent type to use in a CREATE TABLE statement.You cannot store cursor variables in an associative array, nested table, or varray.Cursors and cursor variables are not interoperable; that is, you cannot use one where the other is expected. For example, you cannot reference a cursor variable in a cursor FOR loop

 192 views

19⟩ What will happen after commit statement?

Cursor C1 is

Select empno,

ename from emp;

Begin

open C1; loop

Fetch C1 into

eno.ename;

Exit When

C1 %notfound;-----

commit;

end loop;

end;

The cursor having query as SELECT .... FOR UPDATE gets closed after COMMIT/ROLLBACK.

The cursor having query as SELECT.... does not get closed even after COMMIT/ROLLBACK.

 175 views