adspace


Dear All,



Question for this Week



Find out possible error(s) (either at compile
time or at runtime) in the following PL/SQL block. State
the reason(s) and correct the errors.



Declare

Cursor C1 is select ename, sal, comm from emp;

Begin

For i in C1 Loop

If i.comm between 299 and 999 then

Dbms_output.put_line(i.Ename || ‘
** Good Commission’);

Elsif i.comm > 999 then

Dbms_output.put_line(i.Empno || ‘
** Very Good Commission’);

close C1;

Else

Dbms_output.put_line(i.Ename || ‘
** ’ ||nvl(i.comm,‘O’));

End if;

End Loop;

End;

Answer Posted / rinson

Nobody mentioned errors..(both runtime and compile time)

let's go through the errors

A. compile time errors

1. Encountered symbol "‘" when expecting single qoutes
double quotes etc.
2. When we replace all these symbols to single quotes
next error -- > empno must be declared will come,
since it is to be declared in cursor C1.Here they
may be expecting ename instead of empno.
3. Then it will show next error-->
Numeric or value error since nvl function contains
different datatypes.we can change this to 0.

Now all compile time errors removed.

B. Run Time Errors

1. Since cursor for loop implicitly open,fetch and close
cursor , there is no need to close cursor in second if
condition.Actually compiler will not allow to close a
cursor in a cursor for loop.

it will throw the run time error
ora-01001 invalid cursor.
By removing close c1; all errors will be removed.

PL/SQL code without any errors is exact as given above
by Ramprasad.

Thanks

Rinson KE

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can delete statement be rollbacked?

1061


how to start mysql server? : Sql dba

1275


Is inner join faster than left join?

1284


what are aggregate and scalar functions? : Sql dba

1137


Is primary key clustered index?

1024


what are all the common sql function? : Sql dba

1137


What is the current version of sql?

1100


What is your daily office routine?

2351


Can we use distinct and group by together?

1143


what is sql server agent? : Sql dba

1186


what is dbms? : Sql dba

1067


what are the advantages of sql ? : Sql dba

1148


what is collation? : Sql dba

1235


If a cursor is open, how can we find in a pl/sql block?

1249


how many tables will create when we create table, what are they? : Sql dba

1151