使用查询创建临时表空间以确定Oracle中的大小

时间:2012-02-17 20:42:51

标签: oracle10g tablespace

我正在尝试创建一个临时表空间,其大小是'TEMP'表空间的一半。

类似于:

create temporary tablespace Temptest
TempFile 'somepath'
size ?M;

在哪里? =

select bytes/2/1024/1024 
  from dba_temp_files 
 where tablespace_name='TEMP';

1 个答案:

答案 0 :(得分:1)

您可以编写使用动态SQL的PL / SQL块。像

这样的东西
DECLARE
  l_current_temp_size_mb NUMBER;
  l_sql_stmt             VARCHAR2(1000);
BEGIN
  SELECT SUM(bytes)/1024/1024
    INTO l_current_temp_size
    FROM dba_temp_files
   WHERE tablespace_name = 'TEMP';

  l_sql_stmt :=
    'CREATE TEMPORARY TABLESPACE tempTest TEMPFILE <<somepath>> size ' || 
       to_char( l_current_temp_size_mb / 2 ) ||
       ' M';
  -- Print out the SQL statement or write it to a table so that if there is an error, 
  -- you know what SQL statement was generated and can debug it.
  dbms_output.put_line( l_sql_stmt ); 
  EXECUTE IMMEDIATE l_sql_stmt;
END;