Click here to Skip to main content
15,885,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create Oracle Stored procedure which drops table (if exists) and creates a temp table. Then dumps a data into the temp table

It is giving me complier error:
"Error(12,1): PLS-00103: Encountered the symbol "CREATE""

Can someone please provides some guidance or directions on how to get around this error?

SQL
create or replace PROCEDURE SP_GET_USERS(STARTDATE_IN IN DATE, ENDDATE_IN IN DATE)
IS
CANTIDAD integer;
BEGIN

SELECT COUNT(*) INTO CANTIDAD FROM USER_TABLES WHERE TABLE_NAME = TEMP_TABLE1;
IF (CANTIDAD >0) THEN
    execute immediate 'DROP TABLE ' || TEMP_TABLE1
END IF;
--END;

Execute Immediate
'CREATE GLOBAL TEMPORARY TABLE TEMP_TABLE1
        (USER_ID number,
         Role CHAR(30),
		 MONTH_PER CHAR(20),
         COUNT number)
      ON COMMIT DELETE ROWS;'
 END IF;    

INSERT INTO TEMP_TABLE1
(USER_ID, ROLE, MONTH_PER, COUNT) 
SELECT    *
FROM     TABLE1  
WHERE MONTH_PER BETWEEN STARTDATE_IN AND ENDDATE_IN
END;
Posted
Updated 20-Nov-15 7:10am
v2

1 solution

Creating a stored procedure and what it is doing are 2 completely different things.
http://www.w3schools.com/sql/[^]

Your code need some checking, I see one IF and two END IF
I guess the error message is only the first one.
 
Share this answer
 
Comments
Member 12155899 20-Nov-15 15:40pm    
I did not post all the SQL codes, I only posted where I think the issue is.
Patrice T 20-Nov-15 16:28pm    
Good luck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900