Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

CTE within Stored procedure

3240573May 17 2016 — edited May 18 2016

I'm new to oracle. I am trying to use CTE's within a stored procedure.

Here's the sample code:

create or replace PROCEDURE "TEST"

AS

BEGIN

WITH CTE (StudentID, Studentname, Coursename) AS (

            SELECT Distinct A.StudentID,B.Studentname ,C.Coursename  FROM Student A

JOIN Studentname B ON A.studentid=b.studentid

JOIN Course C on C.CourseID=B.courseid

Where B.studenttype=4 and B.studentid is not null )

INSERT INTO studenthistory

select  A.studentregistrationumber,A.studentregdate,B.studentname from studentregistration A

Inner Join cte b on A.studentid=b.studentid

END TEST;

This is the error I get,

Error(6,1): PL/SQL: SQL Statement ignored

Error(11,2): PL/SQL: ORA-00928: missing SELECT keyword

Thanks in advance

This post has been answered by AndrewSayer on May 17 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2016
Added on May 17 2016
7 comments
5,391 views