【发布时间】:2020-04-15 19:17:50
【问题描述】:
当我尝试在 oracle 中编译此存储过程中的几个变量时,我得到 ORA-00904 Invalid Identifier 但不知道原因;所有工作存储事件都在代码的 DECLARE 块中声明,并且模式中的变量也都正确定义。 有没有人遇到过这个错误和/或知道如何解决它?
这是我正在使用的架构的 DDL
CREATE TABLE history
("history_id" number(4) primary key,
"history_dt" date not null,
"history_time" timestamp not null,
"booking_cost" varchar2(50) not null,
"booking_status" varchar2(50) not null
);
CREATE TABLE attendees
("attendee_id" number(8) primary key,
"attendee_name" varchar2(50) not null,
"attendee_class" number(4) not null,
"attendee_school" varchar2(50) not null,
"attendee_status" varchar2(50) not null
);
CREATE TABLE event
("event_id" number(10) primary key,
"event_name" varchar2(100) not null,
"event_location" varchar2(100) not null,
"event_size" number(4) not null,
"start_dt" date not null,
"end_dt" date not null,
"class_restriction" number(4) not null,
"school_restriction" varchar2(100) not null
);
CREATE TABLE reservation
("reservation_id" number(3) primary key,
"event" number(10) references event("event_id"),
"attendee" number(8) references attendees("attendee_id"),
"booking" number(4) references history("history_id"),
"reservation_status" varchar2(50) not null
);
这些是我收到的错误消息
编译失败,第 19 行 (15:38:10) PL/SQL: ORA-00904: "END_DT": invalid identifierCompilation failed,line 18 (15:38:10)
PL/SQL:SQL 语句被忽略编译失败,第 26 行 (15:38:10) PLS-00302:必须声明组件“EVENT_ID”编译失败,第 26 行 (15:38:10) PL/SQL: ORA-00904: "RESERVATION"."EVENT_ID": invalid identifierCompilation failed,line 26 (15:38:10)
PL/SQL: SQL 语句被忽略编译失败,第 36 行 (15:38:10) PL/SQL: ORA-00904: "EVENT_ID": invalid identifierCompilation failed,line 35 (15:38:10)
PL/SQL:语句忽略编译失败,第 51 行 (15:38:10) PL/SQL: ORA-00947: not enough valuesCompilation failed,line 51 (15:38:10)
create or replace procedure Event_Planning
(arg_event_id in number, arg_student_id in number)
IS
ws_event_name varchar(100);
ws_capacity number;
ws_event_school varchar2(4);
ws_event_class number;
past_event exception;
capacity exception;
school exception;
class exception;
BEGIN
--Test for active event
select max(event_name) into ws_event_name from event
where event_id = arg_event_id and end_dt > SYSDATE;
if ws_event_name is null
then raise past_event;
end if;
--Test for capacity
select max(event_capacity) into ws_capacity from event JOIN reservation ON event.event_id = reservation.event_id
where event_id = arg_event
and event_capacity > reservation_size;
if ws_capacity is null
then raise capacity;
end if;
--Test for restricted school
select max(school_restriction) into ws_event_school from event
where event_id = arg_event_id;
if ws_event_school = arg_school
then raise school;
end if;
--Test for restricted class
select max(class_restriction) into ws_event_class from event
where event.id = arg_event;
if ws_event_class = arg_class
then raise class;
end if;
--Update reservation table
insert into reservation values
(Seq.nextval, arg_event, arg_student);
update reservation
set reservation_size = reservation_size + 1;
--Exceptions
Exception
when past_event
then raise_application_error(-20001, 'Event has passed');
when capacity
then raise_application_error(-20002, 'Event at capacity');
when school
then raise_application_error(-20003, 'Invalid school');
when class
then raise_application_error(-20004, 'Invalid class');
END;
【问题讨论】:
-
创建过程
AS -
@EduardoAlmeida 创建或替换过程 X 是...就好了
-
如果您要显示实际的、完整的和完整的错误消息,它将帮助我们了解我们需要将注意力集中在哪里。顺便说一句,您对“工作存储”一词的使用——没有错——自从我作为 COBOL 程序员的日子以来,我就没有听说过这个词! :-)
-
@EduardoAlmeida 我相信下次轮到你来接我了 :)
-
@EduardoAlmeida 尽管
is/as关键字在这里可以互换,但create procedure xxx as读起来更好。procedure xxx is在包中更有意义。
标签: sql oracle stored-procedures plsql