plsql - 如何正确处理 PL SQL 中的触发器?
问题描述
create or replace trigger grade_
before insert on student_det
for each row
BEGIN
CASE
WHEN new.grade > 10 then dbms_output.put_line('A');
WHEN new.grade > 20 then dbms_output.put_line('A+');
ELSE dbms_output.put_line('Failed');
END
END
当我运行上面的代码时,我收到以下错误
Error at line 4: PLS-00103: Encountered the symbol "WHEN" when expecting one of the following:
:= . ( % ;
The symbol ";" was substituted for "WHEN" to continue.
Error at line 6: PLS-00103: Encountered the symbol "END" when expecting one of the following:
:= . ( % ;
Error at line 5: PLS-00103: Encountered the symbol "ELSE" when expecting one of the following:
:= . ( % ;
The symbol ";" was substituted for "ELSE" to continue.
2. before insert on student_det
3. for each row
4. BEGIN
5. CASE new.grade
6. WHEN 10 then dbms_output.put_line('A')
有人可以帮我吗?我对触发器比较陌生。我的想法是每当我将新记录插入 student_det 记录时简单地调用此触发器,并根据给定的条件显示学生获得的成绩。
解决方案
一些语法错误:
CREATE OR REPLACE TRIGGER grade_
BEFORE INSERT
ON student_det
FOR EACH ROW
BEGIN
CASE
WHEN :new.grade > 10 /* :new instead of new */
THEN
DBMS_OUTPUT.put_line ('A');
WHEN :new.grade > 20 /* :new instead of new */
THEN
DBMS_OUTPUT.put_line ('A+');
ELSE
DBMS_OUTPUT.put_line ('Failed');
END CASE; /* missing CASE and semicolon */
END; /* missing semicolon */
推荐阅读
- iterator - 迭代序列后未触发聚合序列中的 OnComplete
- r - 同样的错误来自哪里,执行 LMER 测试?附资料
- java - Java - 如何从 xml 验证文件中捕获所有异常/错误
- javascript - 锁定命令 Discord.js
- python - scrapy/regex 从 html 获取 json_object
- date - SAS 94 如何计算距离下一条记录的天数
- html - 如何在标签后向文本区域添加换行符
- python - 使用 Python Pandas 处理数据并进行数据透视
- javascript - 使用 Kaltura VPaaS API,上传视频后如何获得 READY 状态?
- c# - System.Net.WebSockets 在断开连接后将套接字留在 close_wait