How can I write a neat PL/SQL stored procedure that can execute against a given database link?
It gets really messy, writing stuff like this:
PROCEDURE my_proc(aDbLink IN VARCHAR2)
IS
BEGIN
EXECUTE IMMEDIATE '
SELECT mycolumn, anothercolumn
FROM MYTABLE@' || aDbLink || '
WHERE such-and-such...'
END
as the query gets bigger.
What else might I do? I’m stuck using stored procedures, and expect that my procedures will execute against one of several db links.
The simplest way to avoid using dynamic SQL would be to create synonyms.
Your stored procedures would then simply refer to the synonym
MyTableRemote. You could then have a separate method that took the database link name as a parameter and changed all the synonyms to point at the database link.