• delimiter 与 存储过程


    1.如此执行语句不行,需要在 delimiter

      IF not EXISTS (
            SELECT
              *
            FROM
              information_schema. COLUMNS
            WHERE
              table_schema = 'thc_rcm'
              AND table_name = 'Cs_AccountBillDetail'
              AND column_name = 'shopSetItemId'
        ) THEN
        ALTER TABLE `thc_rcm`.`Cs_AccountBillDetail`
        ADD COLUMN `shopSetItemId` varchar(64) DEFAULT NULL COMMENT '套餐的订单明细ID' AFTER `itemId`;
     END IF;

     

    2.这样写也不行,因为这样的语句必须在存储过程里执行

    DELIMITER //
      IF not EXISTS (
            SELECT
              *
            FROM
              information_schema. COLUMNS
            WHERE
              table_schema = 'thc_rcm'
              AND table_name = 'Cs_AccountBillDetail'
              AND column_name = 'shopSetItemId'
        ) THEN
        ALTER TABLE `thc_rcm`.`Cs_AccountBillDetail`
        ADD COLUMN `shopSetItemId` varchar(64) DEFAULT NULL COMMENT '套餐的订单明细ID' AFTER `itemId`;
     END IF;
      END//
    DELIMITER ;

     

     

    3.OK

     

    DELIMITER //
    CREATE PROCEDURE thc_rcm_change ()
      BEGIN
      IF not EXISTS (
            SELECT
              *
            FROM
              information_schema. COLUMNS
            WHERE
              table_schema = 'thc_rcm'
              AND table_name = 'Cs_AccountBillDetail'
              AND column_name = 'shopSetItemId'
        ) THEN
        ALTER TABLE `thc_rcm`.`Cs_AccountBillDetail`
        ADD COLUMN `shopSetItemId` varchar(64) DEFAULT NULL COMMENT '套餐的订单明细ID' AFTER `itemId`;
     END IF;
      END//
    DELIMITER ;
    CALL thc_rcm_change ();
    DROP PROCEDURE
    IF EXISTS thc_rcm_change;

     

     

     4.将添加字段变为删除字段则执行不通过,待解???????????

     

    DELIMITER //
    CREATE PROCEDURE thc_rcm_change ()
      BEGIN
      IF not EXISTS (
            SELECT
              *
            FROM
              information_schema. COLUMNS
            WHERE
              table_schema = 'thc_rcm'
              AND table_name = 'Cs_AccountBillDetail'
              AND column_name = 'shopSetItemId'
        ) THEN
        ALTER TABLE `thc_rcm`.`Cs_AccountBillDetail`
        drop COLUMN shopSetItemId;
     END IF;
      END//
    DELIMITER ;
    CALL thc_rcm_change ();
    DROP PROCEDURE
    IF EXISTS thc_rcm_change;

     


    错误提示

    Query execution failed

    原因:
    SQL 错误 [1064] [42000]: 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 ') THEN
    ALTER TABLE `thc_rcm`.`Cs_AccountBillDetail` drop column setMealDetai' at line 1

    Query execution failed


    注:

    windows navicat 中可以执行成功

    Mac DBeaver中执行不成功 

  • 相关阅读:
    第 425 期 Python 周刊
    第 423 期 Python 周刊
    第423期 Python 周刊
    Python Weekly 422
    第421期 Python 周刊
    第420期 Python 周刊
    LeetCode 3: 无重复字符的最长子串 Longest Substring Without Repeating Characters
    Python Weekly 419
    LeetCode 771: 宝石与石头 Jewels and Stones
    LeetCode 652: 寻找重复的子树 Find Duplicate Subtrees
  • 原文地址:https://www.cnblogs.com/guchunchao/p/9861363.html
Copyright © 2020-2023  润新知