PL / SQL触发错误

时间:2014-10-30 04:54:17

标签: sql oracle plsql triggers

问题: 有三个角色。 1)学生2)助教(TA)3)老师。学生和助教可以是同一个人,但角色不同。学生和教师都有一个名为unity id的唯一ID。他们是课程表中的各种课程,学生可以参加,TA可以协助。他们是与每门课程相关的各种主题,可以在多个课程中出现。主题出现在不同的表格中。 规则: 1)TA不能协助他/她是学生的课程。 2)通知已发送给正在参加课程的教师。

要求:每当TA注册(填写在“TA”表中)时,如果TA和学生的主题相同,我们必须向教师发送通知(Course_roster表中的Cid对应于TOPICS表中的主题)重叠。

所以,我创建了一个Notification表,当触发器触发时会填充该表。此外,我创建了一个触发器,我已经搞砸了,因为我第一次做PL / SQL。

我附加了来自TA表,Course_roster表,主题表和通知表布局的样本数据

Course_Roster Table

CID	            unityid
CSC440FALL14	tregan
CSC440FALL14	mfiser
CSC440FALL14	jander
CSC440FALL14	mjones
CSC540FALL14	aneela
CSC540FALL14	mjones
CSC540FALL14	jmick
CSC540FALL14	tregan


TA Table

CID             unityid
CSC440FALL14	aneela
CSC440FALL14	jmick
CSC540FALL14	jharla
CSC541FALL14	jmoyer

Topics Table

CID	            TID	    Topic Name
		
CSC440FALL14	100  	Introduction to database design
CSC440FALL14	101 	SQL:Queries, Constraints,Triggers
CSC540FALL14	500  	Introduction to database design
CSC540FALL14	501	    Storing data: Disks and Files
CSC540FALL14	502     Primary File Organizations
CSC540FALL14	503 	Tree Structures
CSC541FALL14	502 	Primary File Organizations
CSC541FALL14	503 	Tree Structures


Notification table

t_unityid	text	s_unityid	timestamp

CREATE OR REPLACE TRIGGER tr_TA
AFTER
INSERT OR UPDATE 
ON TA
FOR EACH ROW
BEGIN
    DECLARE tid1 dbms_sql.number_table;
    DECLARE tid2 dbms_sql.number_table;
    DECLARE tid3 dbms_sql.number_table;
    DECLARE @unityid varchar2;
    DECLARE @unityid2 varchar2;
            
            Select @unityid= unityid from inserted
            Select @unityid2=unityid from COURSES Where COURSES.CID=inserted.CID
            
            Select tid1=t.TID from TOPICS t,COURSE_ROSTER c where t.CID=c.CID and c.UNITYID=UNITYID
            Select tid2=t.TID from TOPICS t,inserted where t.CID=inserted.CID

            tid3 := tid2 multiset intersect tid1;
        IF tid3.Count > 0
            insert into notification (unityid, notice, ta_unityid)
            values(@unityid2, 'Subject topic of TA is matching with course topics taken.',@unityid)
        ELSE
            PRINT 'TA ok to register'
END

代码中有很多错误,因为我不知道代码的去向。我非常感谢帮助让我通过。提前谢谢。

0 个答案:

没有答案
相关问题