0

I need help in altering multiple tablespaces at once in Oracle Database 11g. My particular scenario is that this command will be used in a shell script to set all of the tablespaces in read-write mode for upgrade purposes. The problem is that each server has a different number of tablespaces, so i can't hardcode the names right in. To solve this I will make a list of all the relevant tablespaces by using the datafiles and I want to pass this list it as an argument.

For instance, you alter one tablespace as such :

ALTER TABLESPACE DATA1 READ ONLY;

I want to do something of the likes :

ALTER TABLESPACE DATA1,DATA2,DATA3 READ ONLY;

Is this possible? If so what is the exact syntax. Thanks in advance!

3

The syntax for the alter tablespace statement only supports one tablespace at a time, you can't list more than one as you're trying to.

If you're scripting that command already, simply have your script issue multiple alter tablespace statements rather than one.

If you're generating your list of tablespaces from dba_tablespaces, you can dynamically alter the tablespaces from that with something like:

begin
  for tbs in (select tablespace_name from dba_tablespaces where [your conditions])
  loop
    execute immediate 'alter tablespace '||tbs.tablespace_name||' read only';
  end loop;
end;
/
  • Your solution worked for me. Thank you for the help! – robertpas Oct 7 '14 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.