USE `test`$$
DROP PROCEDURE IF EXISTS `p_getAllTablesCount`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `p_getAllTablesCount`()
BEGIN
DECLARE tableName VARCHAR (100)
DECLARE tablesn VARCHAR (100)
DECLARE tableCount INT
DECLARE stopFlag INT
DECLARE sqlStr VARCHAR(1000)
-- 注意:请修改数据库名称
DECLARE cursor_name CURSOR FOR SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema='test'
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET stopFlag=1
CREATE TABLE IF NOT EXISTS temp_table(table_name VARCHAR(100),table_count VARCHAR(100))
OPEN cursor_name
REPEAT
FETCH cursor_name INTO tableName
SET sqlStr = CONCAT('SELECT COUNT(1) into @tableCount FROM ', tableName)
SELECT sqlStr INTO @sqlStr
-- select @sqlStr
SELECT @tableCount INTO tableCount
BEGIN
PREPARE stepInsertIntoTable FROM @sqlStr
EXECUTE stepInsertIntoTable
END
SET sqlStr = CONCAT('insert into temp_table values(''',CONCAT(tableName),''',''',CONCAT(tableCount),''')')
SELECT sqlStr INTO @sqlStr
BEGIN
PREPARE stepInsertIntoTable FROM @sqlStr
EXECUTE stepInsertIntoTable
END
UNTIL stopFlag END REPEAT
CLOSE cursor_name
SELECT table_name,table_count FROM temp_table ORDER BY table_count DESC
-- PREPARE step FROM @sql1
-- EXECUTE step
DROP TABLE temp_table
END$$
DELIMITER
不好意思,只能看到您发的图,我只能粗略的模拟一下思路: 使用 date_format() 函数 (mysql自带的函数)
(1) 创建表
create table date_test(dateofmanufacture DATE)
(2) 插入
insert into date_test values(date_format("1983-11-23", "%y-%m-%d"))
(3) 查询
select * from date_test
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)