I am trying to create a trigger for checking capacity, inputs of 2 function get_max_capacity and get_current_capacity have OBJECT_U5 type (My code is below)
CREATE OR REPLACE TYPE object_u5 AS OBJECT (
student_id VARCHAR2(1000),
course_id VARCHAR2(1000),
sec_id VARCHAR2(1000),
semester VARCHAR2(1000),
year NUMBER(4,0),
grade VARCHAR2(3)
);
CREATE OR REPLACE FUNCTION get_current_capacity (
course_register IN object_u5
) RETURN NUMBER IS
current_capacity NUMBER(38);
BEGIN
SELECT
COUNT(*)
INTO current_capacity
FROM
takes
WHERE
course_id = course_register.course_id
AND sec_id = course_register.sec_id
AND year = course_register.year
AND semester = course_register.semester;
END;
CREATE OR REPLACE TRIGGER check_capacity BEFORE
INSERT ON takes
FOR EACH ROW
ENABLE DECLARE
max_capacity NUMBER(4, 0);
current_capacity NUMBER(4, 0);
BEGIN
max_capacity := get_max_capacity(:new);
current_capacity := get_current_capacity(:new);
IF ( max_capacity > cur_capacity ) THEN
dbms_output.put_line('Insert successfully');
ELSE
dbms_output.put_line('The classroom is full! Choose the others');
END IF;
END;
2 errors which were returned: PLS-00049: bad bind variable 'NEW'
:NEWdoes not exist, it is a prefix for a column in the table the trigger is on. You can do something like:NEW.course_id