Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Perulangan MySQL melalui tabel

Coba ini:

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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Mengabaikan apostrof dalam pencarian mysql

  2. PHP PDO Kursor yang dapat digulir MySQL tidak berfungsi

  3. Gagal menginisialisasi database MySQL pada Windows 10

  4. Penomoran baris dengan p:dataTable

  5. Menghubungkan ke Database MySQL Online menggunakan VB.Net