Delimiter and stored procedure

Source: Internet
Author: User
Tags sql error

1. If the statement cannot be executed in this way, you need

If not exists (select * From information_schema. columns where table_schema = 'thc _ RCM 'and table_name = 'cs _ accountbilldetail' and column_name = 'shotitemid') Then alter table 'thc _ RCM '. 'cs _ accountbilldetail 'add column 'show.titemid' varchar (64) default null comment 'order details id' after 'itemid'; end if;

 

 

2. This statement cannot be written because it must be executed in the stored procedure.

Delimiter // if not exists (select * From information_schema. columns where table_schema = 'thc _ RCM 'and table_name = 'cs _ accountbilldetail' and column_name = 'shotitemid') Then alter table 'thc _ RCM '. 'cs _ accountbilldetail 'add column 'show.titemid' varchar (64) default null comment 'order details 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 = 'shotitemid') Then alter table 'thc _ RCM '. 'cs _ accountbilldetail 'add column 'show.titemid' varchar (64) default null comment 'order details id' after 'itemid'; end if; end // delimiter; call thc_rcm_change (); drop procedureif exists thc_rcm_change;

 

 

 

4. If the field to be added is changed to the Deleted field, the operation fails ???????????

 

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 PROCEDUREIF EXISTS thc_rcm_change;

 

Error Message

Query execution failed

Cause:
SQL error [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

 

Delimiter and stored procedure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.