Create a procedure to dynamically add a tablespace
01sar01Jan 6 2011 — edited Jan 7 2011Hi,
I want to create a procedure that will accept two parameters. The name of a tablespace and the name of its datafile, with the path.
i don't know if this will work...currently it gives an error. Is it something that cannot be done using dynamic sql like this or is there another method.
Thanks for your help!
create or replace procedure create_tbs(tbs_name varchar2, filename varchar2)
is
str_tbs varchar2(500);
v_tbs varchar2(100);
begin
str_tbs := 'create tablespace ' || tbs_name || ' datafile '''||filename|| ''' size 1m' ;
select tablespace_name into v_tbs
from sys.dba_tablespaces
where tablespace_name=tbs_name;
dbms_output.put_line('tablespace exists');
exception
when no_data_found then
execute immediate str_tbs;
dbms_output.put_line('tablespace was created');
end;
/
SQL> execute create_tbs('mytab','/u01/app/oracle/oradata/orcl/mytab01.dbf')
ERROR....No such file or directory. (The directory does exist !!)