G-8210: Always use synonyms when accessing objects of another application schema.
Major
Changeability, Maintainability
Reason
If a connection is needed to a table that is placed in a foreign schema, using synonyms is a good choice. If there are structural changes to that table (e.g. the table name changes or the table changes into another schema) only the synonym has to be changed no changes to the package are needed (single point of change). If you only have read access for a table inside another schema, or there is another reason that does not allow you to change data in this table, you can switch the synonym to a table in your own schema. This is also good practice for testers working on test systems.
Example (bad)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | declare l_product_name oe.product.product_name%type; k_price constant oe.product.list_price%type := 1000; begin select product_name into l_product_name from oe.product where list_price > k_price; exception when no_data_found then null; -- handle_no_data_found; when too_many_rows then null; -- handle_too_many_rows; end; / |
Example (good)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | create synonym oe_product for oe.product; declare l_product_name oe_product.product_name%type; k_price constant oe_product.list_price%type := 1000; begin select product_name into l_product_name from oe_product where list_price > k_price; exception when no_data_found then null; -- handle_no_data_found; when too_many_rows then null; -- handle_too_many_rows; end; / |