postgresql批量删除表

CREATE FUNCTION del_ora_table() RETURNS void AS $$
DECLARE
    tmp VARCHAR(512);
DECLARE names CURSOR FOR 
    select tablename from pg_tables where schemaname='public';
BEGIN
  FOR stmt IN names LOOP
    tmp := 'DROP TABLE '|| quote_ident(stmt.tablename) || ' CASCADE;';
    RAISE NOTICE 'notice: %', tmp;
    EXECUTE 'DROP TABLE '|| quote_ident(stmt.tablename) || ' CASCADE;';
  END LOOP;
  RAISE NOTICE 'finished .....';
END;
 
$$ LANGUAGE plpgsql;

--执行函数批量删除表
select del_ora_table();

 

posted @ 2018-07-17 16:21  Luis Yang  阅读(8880)  评论(0编辑  收藏  举报