【问题标题】:Oracle Trigger Error : missing left parenthesisOracle 触发器错误:缺少左括号
【发布时间】:2023-01-10 12:51:30
【问题描述】:

谁能帮我解决这个问题。

CREATE or replace trigger check_limit_to_Y
AFTER INSERT OR UPDATE ON api_user for each row
WHEN EXISTS (SELECT '1' FROM profile b WHERE  NEW.mvno_limit!='Y' and b.mvno_id = NEW.mvno_id)
BEGIN
   raise_application_error (-20999,'MVNO LIMIT MUST BE SET Y FOR ANY REAL MVNO_ID');
END;

我得到了错误

Error report -
ORA-00906: missing left parenthesis
00906. 00000 -  "missing left parenthesis"
*Cause:    
*Action:

【问题讨论】:

  • SELECT RAISE(... 是做什么的? RAISE 是 afaik 语句,而不是可以在 SELECT 子句中使用的函数。
  • 谢谢 。我应该更改为“raise_application_error (-20999,'MVNO LIMIT MUST BE SET BE SET Y FOR ANY REAL MVNO_ID');”
  • 这样做之后你仍然有错误吗?如果是这样,请更新您的问题。
  • 仍然有同样的错误。

标签: sql oracle triggers


【解决方案1】:

这是来自 Oracle 站点:https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/create_trigger.htm#LNPLS01374

WHEN (condition)

Specifies a SQL condition that the database evaluates for each row that the triggering statement affects. If the value of condition is TRUE for an affected row, then tps_body runs for that row; otherwise, tps_body does not run for that row. The triggering statement runs regardless of the value of condition.

The condition can contain correlation names (see "referencing_clause ::="). In condition, do not put a colon (:) before the correlation name NEW, OLD, or PARENT (in this context, it is not a placeholder for a bind variable).

See Also:

Oracle Database SQL Language Reference for information about SQL conditions
Restrictions on WHEN (condition) 

If you specify this clause, then you must also specify at least one of these timing points:

BEFORE EACH ROW

AFTER EACH ROW

INSTEAD OF EACH ROW

The condition cannot include a subquery or a PL/SQL expression (for example, an invocation of a user-defined function).

您的代码似乎不满足最后两个限制(还有:WHEN 关键字后的整个条件必须用括号括起来)。

但是,您似乎需要使用“复合触发器语法”,因为您想要同时处理插入和更新。仔细检查文档

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-18
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多