views:

45

answers:

1

Firstly

I am an oracle newbie, and I don't have a local oracle guru to help me.

Here is my problem / question

I have some SQL scripts which have to be released to a number of Oracle instances. The scripts create stored procedures.
The schema in which the stored procedures are created is different from the schema which contains the tables from which the stored procedures are reading.

On the different instances, the schema containing the tables has different names.

Obviously, I do not want to have to edit the scripts to make them bespoke for different instances.

It has been suggested to me that the solution may be to set up synonyms.

Is it possible to define a synonym for the table schema on each instance, and use the synonym in my scripts?

Are there any other ways to make this work without editing the scripts every time?

Thank you for any help.

+2  A: 

It'd help to know what version of Oracle, but as of 10g--No, you can't make a synonym for a schema.
You can create synonyms for the tables, which would allow you not to specify the schema in the scripts. But it means that the synonyms have to be identical on every instance to be of any use...

The other option would be to replace the schema references with variables, so when the script runs the user is prompted for the schema names. I prefer this approach, because it's less work. Here's an example that would work in SQLPlus:

CREATE OR REPLACE &schema1..vw_my_view AS
  SELECT *
    FROM &&schema2..some_other_table

The beauty of this is that the person who runs the script would only be prompted once for each variable, not every time the variable is encountered. So be careful about typos :)

OMG Ponies
Variables sound like a very sensible option. Thank you very much for the suggestion. I'll give it a try!
AJ
Allan
@Allan: Updated, I don't remember that being an issue on 10g but I also wasn't using them for schema placeholders.
OMG Ponies