Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded Select in Stored Procedure won't work!

Status
Not open for further replies.

KellyStee

Technical User
Jul 30, 2001
106
US
I'm running just a simple query in a stored procedure and one of the fields in the 'Select' clause comes from an additional 'Select' statement (a.k.a. embedded 'Select'). The problem is that the stored procedure won't compile with the embedded select in the code. Is this right? Does anyone know of a way around this issue?

Thanks!!
Kelly
kelly.steensma@us.pwcglobal.com
 
This is my stored procedure code:

CREATE OR REPLACE PROCEDURE SP_KELLY
IS
BEGIN

INSERT INTO TBLKELLY(EMPLOYEE_NBR,
EMPLOYEE_COST)

SELECT E.EMPLOYEE_NBR,
(SELECT SUM(EC.EMPLOYEE_COST)
FROM DUAL
WHERE E.EMPLOYEE_ID = EC.EMPLOYEE_ID)
FROM EMPLOYEE E,
EMPLOYEE_COST EC;

COMMIT;

END;
/

And this is the error I get every time (it's highlights the second 'Select' statement when I get this message):
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:

( ) - + mod not null others <an identifier>


PLEASE HELP!!! It's driving me nuts!!!
 
Try this:

CREATE OR REPLACE PROCEDURE SP_KELLY
IS
BEGIN

INSERT INTO TBLKELLY(EMPLOYEE_NBR,
EMPLOYEE_COST)
SELECT E.EMPLOYEE_NBR,
sum(ec.employee_cost)
FROM EMPLOYEE E,
EMPLOYEE_COST EC
where e.employee_id = ec.employee_id
group by e.employee_nbr;

COMMIT;

END;
/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top