Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create a procedure to dynamically add a tablespace

01sar01Jan 6 2011 — edited Jan 7 2011
Hi,

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 !!)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2011
Added on Jan 6 2011
4 comments
769 views