• Oracle删除临时表


    1.Oracle的临时表分为会话级临时表和事务级临时表
    2.创建语法分别为
    会话临时表:

    CREATE GLOBAL Temporary TABLE TEMPTABLENAME
    ON COMMIT PRESERVE ROWS
    AS
    SELECT .....FROM..
    

    事务临时表:

    CREATE GLOBAL Temporary TABLE TEMPTABLENAME
    ON COMMIT DELETE ROWS
    INSERT INTO TEMPTABLENAME VALUES('','',....)
    

    3.删除临时表
    会话临时表在使用TRUNCATE 或 会话结束后删除掉
    事务临时表在COMMIT和ROLLBACK后自动删除
    存在前面两个前提时,直接用DROP TABLE TEMPTABLENAME

    4.提示会话在使用删除不了,则需要结束了会话才能DROP会话临时表

    SELECT sid, serial# 
    FROM v$session 
    WHERE sid = (SELECT sid FROM v$lock 
    WHERE id1 = (SELECT object_id  FROM dba_objects 
    WHERE object_name = UPPER('TEMPTABLENAME3')));
    
    ALTER system kill session '751,16962';
    
    

    5.批量删除临时表

    declare p_sql varchar(200);
    begin
    for r in (select a.OBJECT_NAME from ALL_OBJECTS a where a.OBJECT_NAME like 'TEMPTABLENAME%') loop
    p_sql:='TRUNCATE TABLE '||r.OBJECT_NAME;
    execute immediate p_sql;
    p_sql:='drop table '||r.OBJECT_NAME;
    execute immediate p_sql;
    end loop;
    end; 
    
  • 相关阅读:
    Hadoop集群安装
    Oracle ORA01555(快照过旧)
    selenium+java+testng+ant环境搭建
    selenium ssl
    watir识别IE版本号
    ruby and watir中timeout类的用法
    使用TestNGxslt
    ruby system用法
    IE6下调用inetcpl.cpl清除COOKIE的方法
    Shell实例:字符串操作 逻辑判断
  • 原文地址:https://www.cnblogs.com/ButterflyEffect/p/14016288.html
Copyright © 2020-2023  润新知