sql >> Databáze >  >> RDS >> Mysql

MySQL procházet tabulky

Zkuste toto:

delimiter //

drop procedure if exists hunt //
create procedure hunt()
begin
    DECLARE done BOOL default false;
    DECLARE tablename CHAR(255);

    DECLARE cur1 cursor for SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS 
        WHERE TABLE_SCHEMA = "wholesale_production" and COLUMN_NAME LIKE "%first%" ;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
    open cur1;

    myloop: loop
        fetch cur1 into tablename;
        if done then
            leave myloop;
        end if;
        set @sql = CONCAT('select * from `wholesale_production`.', tablename, ' where created_at >= ''2012-10-01''');
        prepare stmt from @sql;
        execute stmt;
        drop prepare stmt;
    end loop;

    close cur1;
end //

delimiter ;

call hunt();


  1. Aktualizujte příkaz if pro Oracle

  2. Jak importovat obrovský soubor CSV s 200 00 řádky do MySQL (asynchronní a rychlý)?

  3. Zkopírujte řádek, ale s novým ID

  4. Jak funguje SHOW COLLATION v MariaDB