常用函数
SELECT substring(MD5(RAND()),1,5);
SELECT CEILING(RAND()*1000000);
SELECT CEILING(RAND()*100000)+100000;
函数
DROP FUNCTION IF EXISTS createInvoice;
CREATE FUNCTION `createInvoice`(invoice_date VARCHAR(30), boe_no VARCHAR(30))
RETURNS int
BEGIN
DECLARE invoice_code VARCHAR(30) DEFAULT CONCAT('CODE', CEILING(RAND()*1000000));
UPDATE `cj_cms`.`dev_basic_accounts_payable` SET `invoice_code` = invoice_code WHERE `boe_no` = boe_no;
RETURN 0;
END;
SELECT createInvoice('2020','boe11111');
DROP FUNCTION IF EXISTS `random_string`;
delimiter $$
CREATE FUNCTION `random_string`(n int) RETURNS varchar(255) CHARSET utf8
BEGIN
DECLARE chars_str varchar(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
DECLARE return_str varchar(255) DEFAULT '';
DECLARE i INT DEFAULT 0;
WHILE i < n
DO
SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*62 ),1));
SET i = i +1;
END WHILE;
RETURN return_str;
END; $$
SELECT random_string(10);
存储过程
DROP PROCEDURE IF EXISTS test;
delimiter $$
CREATE PROCEDURE test(IN uid INT)
BEGIN
select * from table_a where userid=uid;
END; $$
delimiter ;
CALL test(100);