How to use a variable from an outer FOR loop to construct an INSERT statement in an inner loop
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0
Oracle Linux Server 7.7
I am trying to reference a value from a FOR LOOP that I've created with a SELECT statement, as a parameter in an INSERT statement within that FOR LOOP.
More specifically, I am trying to use that parameter to assemble a db_link to pull data from.
This block of code works if I hard-code a db_link in it, as such:
BEGIN FOR db IN ( SELECT database_sid FROM STATS.DB_INFO WHERE ENV='P' ) LOOP INSERT INTO STATS.CPU_STATS SELECT db.database_sid, AVG_CPU_UTILIZATION FROM GV$RSRCMGRMETRIC_HISTORY@ORCL.world; END LOOP; END;