I want to do v$session@remotedatabase
where remotedatabase is a variable for a dblink address. Is that possible?
I'm using Apex 4 and trying to get temporary space on all databases.
Current query
select 'Total temp space available in :Database is '||sum(bytes)/1024/1024 ||' mb' from v$tempfile@:Database
yeilds ORA-01729: database link name expected
because the variable isn't resolved correcltly?
You would need to use dynamic SQL in order to have the database link be variable. In PL/SQL, that would look something like
Basically, you need to construct a string that contains the SQL statement and then execute that dynamically generated string (that's more complicated when the SQL statement itself is building up a string as yours is here-- that makes figuring out which single quotes to escape a bit of a challenge).
Depending on what you are trying to do in APEX, however, you may want something a little different. For example, if you are trying to create a report based on this, a regular (non-interactive) report can be populated either from a SQL statement or a function that returns a SQL statement. If that's what you're trying to do, you'd want something like