I have created a database link that works correctly when the following statement is run:
select * from user.table@dblink
Now I want the name of the dblink to be able to be passed into a PL/SQL Procedure such that:
Procedure myProc(dblink varchar2) IS
select * from user.table@dblink;
and calling myProc('aValidDBLink') would return all records from the table in the database linked to via that aValidDBLink.
I've tried several attempts to concatenate the dblink string onto the end of the from clause, but none of it is valid. Aside from resorting to Dynamic PL/SQL is there any way of doing this? In the event that Dynamic PL/SQL is required could you give me some sample code that would achieve the desired effect, as I've never touched on it before.
Thanks in advance
Dynamic SQL is your best bet. If you are on 8.1+, you can use Native Dynamic SQL which is much easier to use then the old dbms_sql package.
Yeah, after browsing a bit longer I found an example of using Execute Immediate. So I've now built up the string successfully (e.g. in v_sql_string) so now if I do an "execute immediate v_sql_string;" inside TOAD then I get no complaints/warnings, etc. However, the results aren't displayed in the data table as they would be if I ran the equivalent static SQL statement. Do dynamic queries *have* to be handled using cursors - or is this just TOAD playing games with me?
Click Here to Expand Forum to Full Width