Hello everyone,

I am having some trouble with a while loop inside a program I've written. Below is the while loop section of my code. When I run the entire program, I get SQL ERROR CODE: -905, SQL ERROR MESSAGE: ORA-00905: missing keyword. Can you please tell me if the syntax I'm using is correct?

Logic for loop....Example: If user entered in 5/15/2001 for the begin_date and 6/15/2003 for the end_date parameter, I would like for the first loop to loop through 5/15/2001-6/15/2001, the second loop to loop through 6/16/2001 - 7/16/2001, etc..... and to only insert into the employee table the hire dates which fall between the specified v_begin_date and v_month and to commit each time it loops. The loop should end when the month reached no longer equals to or is no longer before the maximum hire date in the employee_emp table....I hope this is clear enough. If you need more information, please let me know....

PROMPT Please enter parameters
PROMPT BEGIN_DATE
PROMPT END_DATE
PROMPT
--
DECLARE
v_begin_date DATE;
v_end_date DATE;
v_month DATE;
v_max_date DATE;
v_min_date DATE;
code INTEGER;
execute_code INTEGER;
--
BEGIN
--
--Read in parameters
v_begin_date := '&BEGIN_DATE';
v_end_date := '&END_DATE';
code := dbms_sql.open_cursor;


--If parameters are not null, go ahead
IF (v_begin_date IS NOT NULL) AND (v_end_date IS NOT NULL) THEN
--
dbms_sql.parse (code, 'SELECT MIN(hire_date)
INTO v_min_date
FROM employee_tmp', DBMS_SQL.NATIVE);
result_of_ddl := dbms_sql.execute (code);
--
dbms_sql.parse (code, 'SELECT MAX(hire_date)
INTO v_max_date
FROM employee_tmp', DBMS_SQL.NATIVE);
result_of_ddl := dbms_sql.execute (code);
--
v_month := ADD_MONTHS (v_min_date, 1);
--
WHILE v_month <= v_max_date
LOOP
--
dbms_sql.parse (code, 'INSERT INTO employee
SELECT *
FROM employee_tmp
WHERE hire_date
BETWEEN '''||v_begin_date||'''AND'''||v_month||'''',
dbms_sql.native );
execute_code := dbms_sql.execute (code);
COMMIT;
v_begin_date := v_month + 1;
v_month := ADD_MONTHS (v_begin_date, 1);
--
END LOOP;
END IF;
--
EXCEPTION
DBMS_OUTPUT.PUT_LINE('ERROR OCCURRED');
END;
/


Thanks!

kates