Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:33:55+00:00 2026-06-14T19:33:55+00:00

In this trigger: CREATE TRIGGER `after_insert_normas_revision` AFTER INSERT ON `normas_revision` FOR EACH ROW BEGIN

  • 0

In this trigger:

  CREATE TRIGGER `after_insert_normas_revision`
    AFTER INSERT ON `normas_revision` FOR EACH ROW
    BEGIN

      DECLARE VAR_P_RHID INT;
      DECLARE VAR_P_VERSION INT;

      SELECT MAX(a.`rhID`)
      INTO VAR_P_RHID
        FROM `revision_history` a
        WHERE a.nID = new.`nID`;


      IF VAR_P_RHID IS NULL THEN
        SET VAR_P_VERSION = 0;
      ELSE
        SELECT `version`
          INTO VAR_P_VERSION
          FROM `revision_history` a
          WHERE a.`rhID` = VAR_P_RHID;
      END IF;

      DECLARE VAR_NEW_VERSION INT;
      SET VAR_NEW_VERSION = VAR_P_VERSION + 1;


      INSERT INTO `revision_history`
        (`revID`, `nID`, `userID`, `timestamp`, 
         `prev_rhID`, `version`, `action`, `comment`)
      VALUES
        (new.`revID`, new.`nID`, new.`userID`, CURRENT_TIMESTAMP, VAR_P_RHID, VAR_NEW_VERSION, 'UPDATE', new.`_rev_comment`);

    END

I’m getting this error

Schema Creation Failed: You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near ‘DECLARE VAR_NEW_VERSION INT;
SET VAR_NEW_VERSION = VAR_P_VERSION + 1;
‘ at line 23:

If I remove

DECLARE VAR_NEW_VERSION INT; 
SET VAR_NEW_VERSION = VAR_P_VERSION + 1

or change local variables to session variables (prepending with @) then the code runs allright.


Q. Why does this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:33:56+00:00Added an answer on June 14, 2026 at 7:33 pm

    The problem is in the syntax. It is incorrect.

    All declarations must be at the begining of BEGIND…END clause. User variables you can set wherever you want in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DELIMITER | CREATE TRIGGER RV1 after insert on Iscr for each row call ProcRV1(new.Usere,new.Sub);
I've got this database trigger: CREATE TRIGGER setDescToUpper ON part_numbers AFTER INSERT,UPDATE AS DECLARE
There is something wrong with this trigger. But what? CREATE TRIGGER MYCOOLTRIGGER AFTER INSERT
CREATE OR REPLACE TRIGGER UPDATE_TEST_280510 AFTER insert on TEST_TRNCOMPVISIT declare V_TRNCOMPNO NUMBER(10); CURSOR C1
I have the following trigger: CREATE TRIGGER sum AFTER INSERT ON news FOR EACH
I have this trigger: create or replace trigger t_calctotal after insert or update on
I have a trigger like this CREATE TRIGGER `hrm_to_odm_user` AFTER INSERT ON `ohrm_user` FOR
I have this code (mySql 5.1.36) CREATE TRIGGER problem_description AFTER INSERT ON problem_description FOR
I WANT TO DO SOMETHING LIKE THIS: CREATE TRIGGER addwinner AFTER INSERT ON bids
Starting with a MySQL trigger like this: delimiter # create trigger comments_after_ins_trig after insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.