如何在Oracle sql开发人员中创建触发器?得到错误

以下是我的代码创建触发器如下 .

CREATE or REPLACE TRIGGER sms_trigger
    AFTER INSERT ON student
    FOR EACH ROW
    ENABLE
    DECLARE lclcmd CHAR(255);
    DECLARE res VARCHAR(255);
     BEGIN

      SET lclcmd = CONCAT("php C:/xampp/htdocs/sample/sms_send.php");
      SET res = sys_exec(lclcmd);

    END;

运行上面的代码后得到如下错误

1) Error(1,5): PLS-00103: Encountered the symbol "DECLARE" when expecting 
one 
of the following:     begin function pragma procedure subtype type <an 
identifier>    <a double-quoted delimited-identifier> current cursor delete    
exists prior The symbol "begin" was substituted for "DECLARE" to continue.
2) Error(4,11): PLS-00103: Encountered the symbol "LCLCMD" when expecting 
one of the following:     transaction <a SQL statement>

回答(1)

2 years ago

检查下面的内容,注意concat函数是错误的,你已经添加了一个字符串..来concat .

注意你不必使用声明多一次,也不需要添加 SET ,并且当你想要赋值时你必须放 := .

CREATE or REPLACE TRIGGER sms_trigger
    AFTER INSERT ON student
    FOR EACH ROW
    ENABLE
    DECLARE 
      lclcmd VARCHAR(255);
      res VARCHAR(255);
    BEGIN

       lclcmd := CONCAT('php C:/xampp/htdocs/sample/sms_send.php','something');
      res := sys_exec(lclcmd);

    END;
/