Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Mysql (which differs from Oracle), <code>DECLARE</code> goes after <code>BEGIN</code></p> <p>Your code should be:</p> <pre><code>DELIMITER $$ DROP PROCEDURE IF EXISTS EditEnterprise$$ CREATE PROCEDURE EditEnterprise( IN pEnterpriseId VARCHAR(32), IN pEnterpriseName VARCHAR(64) ) BEGIN /* declare the new variables */ DECLARE nEnterpriseId VARCHAR(32); DECLARE nEnterpriseName VARCHAR(64); /* declare the old variables */ DECLARE oEnterpriseId VARCHAR(32); DECLARE oEnterpriseName VARCHAR(64); SET autocommit = 0; /* get the old variables */ SELECT Enterprise_ID := oEnterpriseId, Enterprise_Name := oEnterpriseName FROM enterprise WHERE Enterprise_ID = pEnterpriseId; /* set the variables with the new inputs */ IF pEnterpriseName IS NULL THEN SET nEnterpriseName = oEnterpriseName; ELSEIF pEnterpriseName = '' THEN SET oEnterpriseName = NULL; ELSE SET nEnterpriseName = pEnterpriseName; END IF; UPDATE enterprise SET Enterprise_Name = nEnterpriseName WHERE Enterprise_ID = pEnterpriseId; COMMIT; END$$ DELIMITER ; </code></pre> <p>I also added the missing <code>;</code>, <code>THEN</code> and <code>END IF</code> keywords. Also, take note that you might have a typo at this line:</p> <pre><code>SET oEnterpriseName = NULL; </code></pre> <p>You probably meant: </p> <pre><code>SET nEnterpriseName = NULL; </code></pre> <hr> <p>Now I think you should reconsider your stored procedure. Indeed, all this could be done in a single SQL query. Do you really need a stored procedure for this? Except if you have a restrictive grants policy it might just be superfluous.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload