0

Following is my Code to create the trigger as follows.

 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;

After running above code getting the error like follows

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> 
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
ALPHA
  • 15
  • 1
  • 6
  • https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA –  Dec 10 '18 at 14:07

1 Answers1

1

Check the below, note that concat function is wrong you have add a string .. to concat.

Note you dont have to use declare more then once, also you dont need to add SET, and you have to put := when you want to assign values.

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;
/
Moudiz
  • 7,211
  • 22
  • 78
  • 156
  • Getting new errors Error(5,7): PL/SQL: Statement ignored and Error(5,14): PLS-00201: identifier 'SYS_EXEC' must be declared – ALPHA Dec 10 '18 at 11:45
  • @ALPHA yes I am here , this sys_exec is it created ? – Moudiz Dec 10 '18 at 12:24
  • that is to execute PHP code in the command line. and that is not created. – ALPHA Dec 10 '18 at 12:26
  • @ALPHA then you need to use UTL_HTTP. few minutes and ill edit my question – Moudiz Dec 10 '18 at 12:31
  • @ALPHA please create a new question about how to execute a cmd in sql because it might envolve few steps.. – Moudiz Dec 10 '18 at 12:44
  • 1
    @ALPHA : `sys_exec` is not an Oracle function and might be an external library. It's not related to the error message showed in this question. You should accept this answer and ask a new one specifically for `sys_exec` – Kaushik Nayak Dec 10 '18 at 13:03
  • @Moudiz Hi bro this is my new link https://stackoverflow.com/questions/53707192/how-to-execute-a-cmd-in-sql – ALPHA Dec 10 '18 at 13:56