日期:2014-05-16 浏览次数:20858 次
DELIMITER // CREATE PROCEDURE sp_crm_insertdata (flag INTEGER(1)) BEGIN DECLARE customer_name VARCHAR(255); DECLARE i INTEGER(11) DEFAULT 10; DECLARE j INTEGER(11) DEFAULT 1000; IF (flag > 0) THEN BEGIN WHILE i < j DO SET customer_name = CONCAT('customer', i); INSERT INTO CUSTOMER( CUSTOMER_NAME, MANAGE_USER, CUSTOMER_TYPE, SCALE, PURVIEW, CREATEOR, BIRTHDAY_REMIND_SMS, BIRTHDAY_REMIND ) VALUES( customer_name, 'admin', '1', '0', '1', 'admin', '1', '1' ); SET i = (i + 1); END WHILE; END; ELSE BEGIN #select i,j; WHILE i < j DO SET customer_name = CONCAT('customer', j); SELECT customer_name; DELETE FROM CUSTOMER WHERE CUSTOMER_NAME = customer_name; SET j = (j - 1); END WHILE; END; END IF; END;
mysql> select count(*) from CUSTOMER; ..... .. +---------------+ | customer12 | +---------------+ 1 row in set (0.86 sec) +---------------+ | customer_name | +---------------+ | customer11 | +---------------+ 1 row in set (0.88 sec) Query OK, 0 rows affected (0.88 sec) mysql> select count(*) from CUSTOMER; +----------+ | count(*) | +----------+ | 0 | +----------+ 1 row in set (0.00 sec) mysql>