1 Replies - 1682 Views - Last Post: 29 October 2006 - 01:33 AM Rate Topic: -----

#1 adb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-October 06

indefinite while loop

Post icon  Posted 28 October 2006 - 03:31 AM

HI,

I want to take maximum 100 records from user at runtime.
I have created sample table name 'Testing' with 'name' & 'city' column.
I have written following code to take max. 100 records from user.
Done SET SERVEROUTPUT ON , SET VERIFY OFF

but loop and IF condition is not working and DBMS_OUTPUT.PUT_LINE msg is not displaying in sequence as written in code.

what is problem with this?

DECLARE
V_NAME VARCHAR(5);
V_CITY VARCHAR(5);
V_CHOICE NUMBER(2);
CNTR NUMBER(5);

BEGIN

CNTR := 1;

WHILE CNTR >= 100
LOOP

DBMS_OUTPUT.PUT_LINE(' ENTER 1 TO INSERT EMPLOYEE INFORMATION ' ); 
DBMS_OUTPUT.PUT_LINE(' ENTER 6 TO EXIT ' ); 
DBMS_OUTPUT.PUT_LINE(' ENTER YOUR CHOICE:' ); 
 
V_CHOICE := &V_CHOICE;
 
IF V_CHOICE <= 5  THEN
 
DBMS_OUTPUT.PUT_LINE( ' ENTER EMPLOYEE NAME: ' ); 
V_NAME := &V_NAME;
 
DBMS_OUTPUT.PUT_LINE( ' ENTER EMPLOYEE CITY: ' ); 
V_CITY := &V_CITY;
INSERT INTO TESTING VALUES(V_NAME,V_CITY);

CNTR := CNTR+1;

ELSEIF V_CHOICE >= 5 THEN

CNTR := 100;
DBMS_OUTPUT.PUT_LINE(' EXIT: ' ); 

END IF;

END LOOP;
END;	 




Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: indefinite while loop

#2 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: indefinite while loop

Posted 29 October 2006 - 01:33 AM

View Postadb, on 28 Oct, 2006 - 03:31 AM, said:

HI,

I want to take maximum 100 records from user at runtime.
I have created sample table name 'Testing' with 'name' & 'city' column.
I have written following code to take max. 100 records from user.
Done SET SERVEROUTPUT ON , SET VERIFY OFF

but loop and IF condition is not working and DBMS_OUTPUT.PUT_LINE msg is not displaying in sequence as written in code.

what is problem with this?

If you have a look, it seems that you have made a logic error in the condition to the loop

CNTR=1 sets the value to less than 100, so the loop never executes...

Fix that then move on to the if statement;

DECLARE

CNTR := 1;

WHILE CNTR >= 100
LOOP

  CNTR := CNTR+1;

END LOOP;
END;	 



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1