SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
  #1 (permalink)  
Old 10-16-2007, 05:02 AM
Unregistered
 
Posts: n/a
Default ANY dialect question:

cursor based thread


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;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 11-06-2007, 03:11 PM
puneeth
 
Posts: n/a
Exclamation ANY answer. Re: cursor based thread

The possible errors are
-> There is no statement to exit from loop
->The crusor to be "fetched" into a another variable declared with %row type
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 07:43 AM
anna_2k2 anna_2k2 is offline
Junior Member
 
Join Date: Nov 2007
Posts: 2
anna_2k2 is on a distinguished road
Default ANY answer. Re: cursor based thread

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Moderation Tools:



All times are GMT. The time now is 06:15 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8