Results 1 to 6 of 6
  1. #1
    Join Date
    May 2009
    Posts
    56

    Unanswered: Getting error on while loop

    Hey guys, I am new to PL/SQL, but familiar with T-SQL. I am getting an error for the below SQL. Any help is appreciative. Thanks.

    Declare monthInt INTEGER := 201006;

    WHILE monthInt < 201009 LOOP

    insert into SummerData
    select Rx_Month, Drug_Name, Quantity
    from Drug_Data
    where Rx_Month = monthInt

    monthInt := monthInt + 1

    END LOOP

    The Error is

    ORA-06550: line 5, column 16:
    PLS-00103: Encountered the symbol "<" when expecting one of the following:

    := . ( @ % ; not null range default character

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    statements are terminated by semicolon characters

    SELECT SYSDATE FROM DUAL;
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    May 2009
    Posts
    56
    Ok, so where do I need to add semi colons? I tried it a bunch of different ways and I am still getting the error.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by coder_t2 View Post
    Ok, so where do I need to add semi colons?
    At the end of each statement or block as you can see e.g. in the examples for the LOOP statement in the manual:

    http://download.oracle.com/docs/cd/B...s.htm#CJAFAJIA

  5. #5
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    when all else fails Read The Fine Manual
    PL/SQL Control Statements
    Code:
    DECLARE
      done  BOOLEAN := FALSE;
    BEGIN
      WHILE done LOOP
        DBMS_OUTPUT.PUT_LINE ('This line does not print.');
        done := TRUE;  -- This assignment is not made.
      END LOOP;
    
      WHILE NOT done LOOP
        DBMS_OUTPUT.PUT_LINE ('Hello, world!');
        done := TRUE;
      END LOOP;
    END;
    /
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  6. #6
    Join Date
    May 2009
    Posts
    56
    Ok I got it now. A lot of the examples I saw either didn't have the BEGIN END block, and didn't have the semicolons after them and the END LOOP. Thank you guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •