您好,登錄后才能下訂單哦!
--創(chuàng)建刪除所有表的存儲(chǔ)過(guò)程
CREATE OR REPLACE FUNCTION delAllTable()
RETURNS void
AS
$BODY$
DECLARE
tmp VARCHAR(512);
DECLARE names CURSOR FOR
select tablename from pg_tables where tableowner='wxdch';
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;
$BODY$ LANGUAGE 'plpgsql' VOLATILE;
--執(zhí)行存儲(chǔ)過(guò)程
select * from delAllTable() as temp;
--創(chuàng)建刪除所有序列號(hào)的存儲(chǔ)過(guò)程
CREATE OR REPLACE FUNCTION delAllSeq()
RETURNS void AS
$BODY$
DECLARE
tmp VARCHAR(512);
DECLARE names CURSOR FOR
select * from pg_class where relowner=(select usesysid from pg_user where usename='wxdch') and relkind='S' ;
BEGIN
FOR stmt IN names LOOP
tmp := 'DROP sequence '|| quote_ident(stmt.relname) || ' CASCADE;';
RAISE NOTICE 'notice: %', tmp;
EXECUTE 'DROP sequence '|| quote_ident(stmt.relname) || ' CASCADE;';
END LOOP;
RAISE NOTICE 'finished .....';
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION delAllSeq() OWNER TO postgres;
--執(zhí)行存儲(chǔ)過(guò)程
select * from delAllSeq() as temp;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。