1.执行mysql存储过程,提示:
illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT)
2.尝试更改数据库的字符串
没有解决问题
我想存储过程当中设计的两个表都是在同一个数据库下,按道理来说字符集是相同的。
3.修改sql,使用完全限定名
原来的sql如下,插入表没有使用完全限定名:
DELIMITER //
CREATE PROCEDURE generate_data()
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE random_apply_no VARCHAR(50);
WHILE i <= 10000 DO
SET random_apply_no = CONCAT('APPLY_', LPAD(i, 4, '0'));
-- 生成插入数据的SELECT子句,并直接插入到user_base表中
INSERT INTO user_base (id, apply_no, batch_date, car_no, created_date, due_bill_no, hash_key, id_no, id_type, last_modified_date, phone, project_no, remark, sex, user_id, user_name, version)
SELECT
i,
random_apply_no,
CURDATE(),
CONCAT('CAR_', LPAD(i, 4, '0')),
NOW(),
random_apply_no,
MD5(CONCAT('ID_', LPAD(i, 4, '0'))),
CONCAT('ID_', LPAD(i, 4, '0')),
'IDENTITY',
NOW(),
CONCAT('PHONE_', LPAD(i, 4, '0')),
'WS10043190001',
NULL,
IF(i % 2 = 0, 'MALE', 'FEMALE'),
CONCAT('USER_', LPAD(i, 4, '0')),
CONCAT('USER_', LPAD(i, 4, '0')),
NULL
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM user_base WHERE apply_no = random_apply_no
)
LIMIT 10;
-- 生成插入数据的SELECT子句,并直接插入到user_bank_card表中
INSERT INTO user_bank_card (id, user_id, id_no, bank_name, bank_code, bank_card_no, phone, version, created_date, last_modified_date, project_no, due_bill_no, agreement_no, apply_no, account_name, is_default, src_req_sn)
SELECT
i,
CONCAT('USER_', LPAD(i, 4, '0')),
CONCAT('ID_', LPAD(i, 4, '0')),
CONCAT('BANK_', LPAD(i, 4, '0')),
CONCAT('BANK_CODE_', LPAD(i, 4, '0')),
CONCAT('BANK_CARD_', LPAD(i, 4, '0')),
CONCAT('PHONE_', LPAD(i, 4, '0')),
NULL,
NOW(),
NOW(),
'WS10043190001',
random_apply_no,
CONCAT('AGREEMENT_', LPAD(i, 4, '0')),
random_apply_no,
CONCAT('ACCOUNT_', LPAD(i, 4, '0')),
1,
CONCAT('REQ_', LPAD(i, 4, '0'))
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM user_bank_card WHERE apply_no = random_apply_no
)
LIMIT 10;
SET i = i + 10;
END WHILE;
END //
DELIMITER ;
修改sql:
DELIMITER //
CREATE PROCEDURE generate_data2()
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE random_apply_no VARCHAR(50);
WHILE i <= 10000 DO
SET random_apply_no = CONCAT('APPLY_', LPAD(i, 4, '0'));
-- 生成插入数据的SELECT子句,并直接插入到user_base表中
INSERT INTO acc_loan.user_base (id, apply_no, batch_date, car_no, created_date, due_bill_no, hash_key, id_no, id_type, last_modified_date, phone, project_no, remark, sex, user_id, user_name, version)
SELECT
i,
random_apply_no,
CURDATE(),
CONCAT('CAR_', LPAD(i, 4, '0')),
NOW(),
random_apply_no,
MD5(CONCAT('ID_', LPAD(i, 4, '0'))),
CONCAT('ID_', LPAD(i, 4, '0')),
'IDENTITY',
NOW(),
CONCAT('PHONE_', LPAD(i, 4, '0')),
'WS10043190001',
NULL,
IF(i % 2 = 0, 'MALE', 'FEMALE'),
CONCAT('USER_', LPAD(i, 4, '0')),
CONCAT('USER_', LPAD(i, 4, '0')),
NULL
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM user_base WHERE apply_no = random_apply_no
)
LIMIT 10;
-- 生成插入数据的SELECT子句,并直接插入到user_bank_card表中
INSERT INTO acc_loan.user_bank_card (id, user_id, id_no, bank_name, bank_code, bank_card_no, phone, version, created_date, last_modified_date, project_no, due_bill_no, agreement_no, apply_no, account_name, is_default, src_req_sn)
SELECT
i,
CONCAT('USER_', LPAD(i, 4, '0')),
CONCAT('ID_', LPAD(i, 4, '0')),
CONCAT('BANK_', LPAD(i, 4, '0')),
CONCAT('BANK_CODE_', LPAD(i, 4, '0')),
CONCAT('BANK_CARD_', LPAD(i, 4, '0')),
CONCAT('PHONE_', LPAD(i, 4, '0')),
NULL,
NOW(),
NOW(),
'WS10043190001',
random_apply_no,
CONCAT('AGREEMENT_', LPAD(i, 4, '0')),
random_apply_no,
CONCAT('ACCOUNT_', LPAD(i, 4, '0')),
1,
CONCAT('REQ_', LPAD(i, 4, '0'))
FROM dual
WHERE NOT EXISTS (
SELECT 1 FROM user_bank_card WHERE apply_no = random_apply_no
)
LIMIT 10;
SET i = i + 10;
END WHILE;
END //
DELIMITER ;
执行成功!