6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQL プロシージャサンプル

Last updated at Posted at 2014-03-14
Function@MySQL
CREATE PROCEDURE `p.resource-update`(
     OUT _ret         VARCHAR(255),
     IN  resource      INT,
     IN  resource_name VARCHAR(255),
     IN  resource_note TEXT       
)
BEGIN

   DECLARE val BOOLEAN;
   DECLARE EXIT HANDLER FOR SQLEXCEPTION
   BEGIN
     ROLLBACK;
   END;
 
   SET _ret = 'ERROR00';
 
   START TRANSACTION;
 
   main_proc: BEGIN

      /* resource の存在チェック */
      IF NOT `baihu`.`f.resource-p`(resource) THEN
         SET _ret = 'ERROR02';
         LEAVE main_proc;
      END IF;

      /* update */
      UPDATE `baihu`.`rs_resource`
         SET `update-datetime` = now()
           , `name`            = resource_name
           , `note`            = resource_note
       WHERE `resource-id`     = resource;

      SET _ret = NULL; 

   END main_proc;
 
   IF _ret IS NULL THEN
      COMMIT;
   ELSE
      ROLLBACK;
   END IF;

END
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?