truncate-all-tables(위험).sql 1011 B

1234567891011121314151617181920212223242526272829303132
  1. DROP PROCEDURE IF EXISTS trunctables;
  2. DELIMITER ;;
  3. CREATE PROCEDURE trunctables(theDb varchar(64))
  4. SQL SECURITY INVOKER
  5. BEGIN
  6. declare tname varchar(64);
  7. declare table_except text;
  8. declare is_found int;
  9. declare tcursor CURSOR FOR
  10. SELECT table_name FROM information_schema.tables WHERE table_type <> 'VIEW' AND table_schema = theDb order by table_name;
  11. set table_except = 'dbr_agroup';
  12. SET FOREIGN_KEY_CHECKS = 0;
  13. OPEN tcursor;
  14. l1: LOOP
  15. FETCH tcursor INTO tname;
  16. if tname = NULL then leave l1; end if;
  17. set is_found = instr(table_except, tname);
  18. insert into aaaa (aaa, bbb) values(table_except, tname);
  19. if is_found = 0 then
  20. set @sql = CONCAT('truncate `', theDB, '`.`', tname, '`');
  21. PREPARE stmt from @sql;
  22. EXECUTE stmt;
  23. DEALLOCATE PREPARE stmt;
  24. end if;
  25. END LOOP l1;
  26. CLOSE tcursor;
  27. SET FOREIGN_KEY_CHECKS = 1;
  28. END ;;
  29. DELIMITER ;
  30. call trunctables('ssokkk_db');