删除全局临时表

发布于 2024-12-12 15:56:02 字数 858 浏览 8 评论 0原文

2 单独的问题。

  1. 我正在使用此脚本删除表[已解决]

    <前><代码>开始 立即执行“删除表名称”; DBMS_OUTPUT.PUT_LINE('全局表TABLE_NAME已删除'); 例外 当其他人 DBMS_OUTPUT.PUT_LINE('全局表 TABLE_NAME 不存在。'); 结尾; /

无论如何,我是否可以区分表“不存在”或它正在其他一些会话中使用(在这种情况下,它将被锁定)并且无法删除)。我不确定是否可以看到 user_tables 中存在该表。我不完全了解权限。

我现在添加了这段代码

WHEN OTHERS THEN
        i_code  :=  SQLCODE;
        v_errm  :=  SUBSTR(SQLERRM, 1, 64);
  if i_code = -942 THEN
    DBMS_OUTPUT.PUT_LINE ('TABLE_NAME doesn''t exist. Script will continue to create it');
  ELSE
    DBMS_OUTPUT.PUT_LINE ('Error dropping temporary table. The error code is ' || i_code || '- ' || v_errm);
  END IF ;

2。我在每个过程的末尾看到.,这样

END PROCEDURE_NAME;
.
/
sho err;

我只是不明白为什么.在这里。是语法还是什么?

2 Separate questions.

  1. I am using this script to drop a table [SOLVED]

    BEGIN
        EXECUTE IMMEDIATE 'DROP TABLE_NAME';
        DBMS_OUTPUT.PUT_LINE ('Global table TABLE_NAME Dropped');
        EXCEPTION
            WHEN OTHERS THEN
                DBMS_OUTPUT.PUT_LINE ('Global table TABLE_NAME Doesn''t exist.');
    END;
    /
    

Is there anyway I can differentiate if table "doesn't exist" or it is being used in some other sessions (in that case it would locked and couldn't be deleted). I am not sure if I can see that table exists in user_tables. I am not fully aware of permissions.

I have added this code now

WHEN OTHERS THEN
        i_code  :=  SQLCODE;
        v_errm  :=  SUBSTR(SQLERRM, 1, 64);
  if i_code = -942 THEN
    DBMS_OUTPUT.PUT_LINE ('TABLE_NAME doesn''t exist. Script will continue to create it');
  ELSE
    DBMS_OUTPUT.PUT_LINE ('Error dropping temporary table. The error code is ' || i_code || '- ' || v_errm);
  END IF ;

2. I see . at the end of each procedure like this

END PROCEDURE_NAME;
.
/
sho err;

I just don't understand why . is here. Is it syntax or what?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

栀子花开つ 2024-12-19 15:56:05

DECLARE GLOBAL TEMPORARY TABLE 语句为当前连接定义临时表。

这些表不驻留在系统目录中并且不是持久的。

临时表仅在声明它们的连接期间存在,并且不能在该连接之外引用。

当连接关闭时,表中的行将被删除,临时表的内存中描述也将被删除。

供您参考http://docs.oracle.com/javadb/10.6。 2.1/ref/rrefdeclaretemptable.html

The DECLARE GLOBAL TEMPORARY TABLE statement defines a temporary table for the current connection.

These tables do not reside in the system catalogs and are not persistent.

Temporary tables exist only during the connection that declared them and cannot be referenced outside of that connection.

When the connection closes, the rows of the table are deleted, and the in-memory description of the temporary table is dropped.

For your reference http://docs.oracle.com/javadb/10.6.2.1/ref/rrefdeclaretemptable.html

初见终念 2024-12-19 15:56:05
  1. 通过在 putty 中运行来关闭 apache 服务器
    cd $ADMIN_SCRIPTS_HOME
    ./adstpall.sh
  2. 删除全局临时表
    drop table t;

这将锻炼..

  1. Down the apache server by running below in putty
    cd $ADMIN_SCRIPTS_HOME
    ./adstpall.sh
  2. Drop the Global temporary tables
    drop table t;

This will workout..

你的笑 2024-12-19 15:56:04

步骤 1. 确定要捕获哪些错误:

如果表不存在:

SQL> drop table x;
drop table x
           *
ERROR at line 1:
ORA-00942: table or view does not exist

如果表正在使用:

SQL> create global temporary table t (data varchar2(4000));

Table created.

在另一个会话中使用该表。 (注意插入后没有提交或任何内容。)

SQL> insert into t values ('whatever');

1 row created.

回到第一个会话,尝试删除:

SQL> drop table t;
drop table t
           *
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already in use

因此要捕获两个错误:

  1. ORA-00942:表或视图不存在
  2. ORA-14452:尝试
    在已使用的临时表上创建、更改或删除索引

查看错误是否为 预定义。他们不是。因此,它们需要像这样定义:

create or replace procedure p as
    table_or_view_not_exist exception;
    pragma exception_init(table_or_view_not_exist, -942);
    attempted_ddl_on_in_use_GTT exception;
    pragma exception_init(attempted_ddl_on_in_use_GTT, -14452);
begin
    execute immediate 'drop table t';

    exception 
        when table_or_view_not_exist then
            dbms_output.put_line('Table t did not exist at time of drop. Continuing....');

        when attempted_ddl_on_in_use_GTT then
            dbms_output.put_line('Help!!!! Someone is keeping from doing my job!');
            dbms_output.put_line('Please rescue me');
            raise;
end p;

结果,首先没有 t

SQL> drop table t;

Table dropped.

SQL> exec p;
Table t did not exist at time of drop. Continuing....

PL/SQL procedure successfully completed.

现在,使用 t

SQL> create global temporary table t (data varchar2(4000));

Table created.

在另一个会话中:

SQL> insert into t values (null);

1 row created.

然后在第一个会话中:

SQL> exec p;
Help!!!! Someone is keeping from doing my job!
Please rescue me
BEGIN p; END;

*
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already in use
ORA-06512: at "SCHEMA_NAME.P", line 16
ORA-06512: at line 1

Step 1. Figure out which errors you want to trap:

If the table does not exist:

SQL> drop table x;
drop table x
           *
ERROR at line 1:
ORA-00942: table or view does not exist

If the table is in use:

SQL> create global temporary table t (data varchar2(4000));

Table created.

Use the table in another session. (Notice no commit or anything after the insert.)

SQL> insert into t values ('whatever');

1 row created.

Back in the first session, attempt to drop:

SQL> drop table t;
drop table t
           *
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already in use

So the two errors to trap:

  1. ORA-00942: table or view does not exist
  2. ORA-14452: attempt to
    create, alter or drop an index on temporary table already in use

See if the errors are predefined. They aren't. So they need to be defined like so:

create or replace procedure p as
    table_or_view_not_exist exception;
    pragma exception_init(table_or_view_not_exist, -942);
    attempted_ddl_on_in_use_GTT exception;
    pragma exception_init(attempted_ddl_on_in_use_GTT, -14452);
begin
    execute immediate 'drop table t';

    exception 
        when table_or_view_not_exist then
            dbms_output.put_line('Table t did not exist at time of drop. Continuing....');

        when attempted_ddl_on_in_use_GTT then
            dbms_output.put_line('Help!!!! Someone is keeping from doing my job!');
            dbms_output.put_line('Please rescue me');
            raise;
end p;

And results, first without t:

SQL> drop table t;

Table dropped.

SQL> exec p;
Table t did not exist at time of drop. Continuing....

PL/SQL procedure successfully completed.

And now, with t in use:

SQL> create global temporary table t (data varchar2(4000));

Table created.

In another session:

SQL> insert into t values (null);

1 row created.

And then in the first session:

SQL> exec p;
Help!!!! Someone is keeping from doing my job!
Please rescue me
BEGIN p; END;

*
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already in use
ORA-06512: at "SCHEMA_NAME.P", line 16
ORA-06512: at line 1
镜花水月 2024-12-19 15:56:04

是的 - 引擎将针对不同的条件抛出不同的异常。

您将更改此部分以捕获异常并执行不同的操作,

  EXCEPTION
      WHEN OTHERS THEN

这里是参考

http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/07_errs.htm

yes - the engine will throw different exceptions for different conditions.

you will change this part to catch the exception and do something different

  EXCEPTION
      WHEN OTHERS THEN

here is a reference

http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/07_errs.htm

痴骨ら 2024-12-19 15:56:03
-- First Truncate temporary table
SQL> TRUNCATE TABLE test_temp1;

-- Then Drop temporary table
SQL> DROP TABLE test_temp1;
-- First Truncate temporary table
SQL> TRUNCATE TABLE test_temp1;

-- Then Drop temporary table
SQL> DROP TABLE test_temp1;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文