我正在尝试创建返回表的过程。因为我已经创建了对象和程序如下。但它给了我编译时错误,
CREATE TYPE INTERN_OBJECT AS OBJECT
( companyTitle VARCHAR2(100),
schoolName VARCHAR2(30),
RANK NUMBER(3),
NUM_INTERNS NUMBER(3));
CREATE TYPE INTERN_TAB AS TABLE OF INTERN_OBJECT;
CREATE OR REPLACE FUNCTION INTERN_DATA_Function RETURN INTERN_TAB
IS
r_INTERN_TAB INTERN_TAB;
r_index number := 0;
BEGIN
r_INTERN_TAB := INTERN_OBJECT();
FOR r IN (select company.title AS title ,school.name AS name ,RANK AS RANK ,count(SID) AS NO_OF_INTERN from school join student on school.SCHID = student.SCHOOLID JOIN INTERN on student.SID = INTERN.SID JOIN COMPANY ON INTERN.CMPID = COMPANY.CMPID GROUP BY company.title,school.name,RANK ORDER BY count(SID) DESC)
LOOP
r_INTERN_TAB.extend;
r_index := r_index + 1;
r_INTERN_TAB(r_index):= INTERN_TAB(r.title, r.name ,r.RANK , r.NO_OF_INTERN);
END LOOP;
return r_INTERN_TAB;
END;
当我点击跑步时,我得到以下错误:
ERROR at line 11: PL/SQL: Statement ignored
1. CREATE OR REPLACE FUNCTION INTERN_DATA_Function RETURN INTERN_TAB
2. IS
3. r_INTERN_TAB INTERN_TAB;
我不知道问题出在哪里。请帮帮我。
答案 0 :(得分:1)
您需要在每个语句后添加/
,特别是如果您在SQL * Plus中运行上述脚本:
CREATE TYPE INTERN_OBJECT AS OBJECT
( companyTitle VARCHAR2(100),
schoolName VARCHAR2(30),
RANK NUMBER(3),
NUM_INTERNS NUMBER(3));
/
CREATE TYPE INTERN_TAB AS TABLE OF INTERN_OBJECT;
/
CREATE OR REPLACE FUNCTION INTERN_DATA_Function RETURN INTERN_TAB
IS
r_INTERN_TAB INTERN_TAB;
r_index number := 0;
BEGIN
r_INTERN_TAB := INTERN_OBJECT();
FOR r IN (select company.title AS title ,school.name AS name ,RANK AS RANK ,count(SID) AS NO_OF_INTERN from school join student on school.SCHID = student.SCHOOLID JOIN INTERN on student.SID = INTERN.SID JOIN COMPANY ON INTERN.CMPID = COMPANY.CMPID GROUP BY company.title,school.name,RANK ORDER BY count(SID) DESC)
LOOP
r_INTERN_TAB.extend;
r_index := r_index + 1;
r_INTERN_TAB(r_index):= INTERN_TAB(r.title, r.name ,r.RANK , r.NO_OF_INTERN);
END LOOP;
return r_INTERN_TAB;
END;
/