Top 50 PL/SQL Interview Questions and answer

 

Try below basic query,Execute it and check the output.

1. Will below query throw error ?

select*from dual;

 

no error

 

2. Will below query throw error ?

 

select*fromdual;

 

 

It will throw ERROR

 

 

3.Find the output of below query

 

declare
begin
select * from dual;
end;

 

 

The above query will not be successful because there is no INTO clause in between BEGIN AND END.
If there is any select statement between begin and end block then we can not use * directly.

 

 

4.Find the output of below query

 

declare
begin
null;
end;

 

 

this will be SUCCESSFUL COMPILED,Because there is NULL between begin and end block.

 

 

5.Find the output of below query

 

declare
begin
var varchar2(1);
end;

 

 

It will throw error.

 

 

6.Find the output of below query

 

declare
var varchar2(1) :=1;
 begin
var :=1;
end;

 

 

compiled successful.

 

 

7.Find the output of below query

 

declare
var varchar2(1) :=1;
begin
var :='a';
dbms_output.put_line('benchpe.com where we can learn '||var);
end;

 

 

Compiled successful with output benchpe.com where we can learn,because Variable VAR is declared as VARCHAR2(1).
So it will accept both number and character.

 

 

8.Find the output of below query

 

declare
var number :=1;
begin
var :='a';
dbms_output.put_line('benchpe.com where we can learn '||var);
end;

 

 

it will throw error due to datatype mismatch.

 

 

9.Find the output of below query

 

declare
vare varchar2(100) :=10;
begin
if vare / 100 then
dbms_output.put_line('benchpe.com where we can learn '||vare);
end;

 

 

Compiled successful with output benchpe.com where we can learn,
Because Variable vare has value 10 and we can divide 10 by 100.

 

 

10.Find the output of below query

 

begin
end;

 

 

This will throw ERROR, because we can not write compile block in this way,
after begin any block or any variable or any function or null should be required.

 

 

11.Find the output of below query

 

set serveroutput on
begin
dbms_output.put_line('benchpe.com where we can learn ');
end;

 

 

executed successfully with output benchpe.com where we can learn.

 

 

12.Find the output of below query

 

set serveroutput on
begin
if 1=2 then
dbms_output.put_line('benchpe.com where we can learn ');
else
dbms_output.put_line('benchpe.com new way to learn ');
end if;
exception;
when others then;
dbms_output.put_line('benchpe');
end;

 

 

executed successfully with output benchpe.com new way to learn ,Because 1 is not equal to 2.

 

 

13.Find the output of below query

 

set serveroutput on
begin
null;
dbms_output.put_line('benchpe.com where we can learn ');
exception;
when others then;
dbms_output.put_line('benchpe');
end;

 

 

executed successfully with output benchpe.com where we can learn.

 

 

Next.