zoukankan      html  css  js  c++  java
  • 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中执行不成功 

  • 相关阅读:
    在IDEA上本地更新同步Git中的更改
    protobuf的序列化和反序列化
    关于Pytorch报警告:Warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead
    990. 等式方程的可满足性
    死锁
    事务隔离
    Lab-1
    软件测试homework3
    TCP/UDP网络连接的固定写法
    软件测试Homework 2
  • 原文地址:https://www.cnblogs.com/guchunchao/p/9861363.html
Copyright © 2011-2022 走看看