| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
cursor based threadQuestion 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; |
|
|||
|
errors in comments
Declare Cursor C1 is select ename, sal, comm from emp; --c1 declaration does not contain empno but you used it in elseif clause.that is wrong. 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'); -- i.empno is not declared close C1; --cursor is closed so you can not reference i which is implicitly declared based on cursor row.so the else clause DOPL statement will through errors Else Dbms_output.put_line(i.Ename || ' ** ' ||nvl(i.comm,'O')); End if; --- there is no exit clause End Loop; End; so these are all the errors you will get. and it looks as if this is a ocp exam question am i right? |