plsql - PL/SQL querying a table on multiple databases -
i'm bit stuck. have table list of database names. want query database name , query database return details "systemtable". i've been trying use 2 cursors not quite working out me (just can't find syntax), pointers/help appreciated.
declare cursor c_dbnames select dbname db_info order name asc; v_curr_dbname varchar2(60); begin open c_dbnames; loop fetch c_dbnames v_curr_dbname; exit when c_dbnames%notfound; begin cursor c_dbdetails select value systemtable@'||v_curr_dbname||' order name asc; v_curr_detail varchar2(60); open c_dbdetails; loop fetch c_dbdetails v_curr_detail; exit when c_dbdetails%notfound; htp.p('<tr><th>'||v_curr_detail||'</th></tr>'); end loop; close c_dbdetails; end; end loop; close c_dbnames; end;
you have adjust little:
declare cursor c_dbnames select 'dual' dbname dual union select 'dual' dbname dual union select 'dual' dbname dual order dbname asc; v_curr_dbname varchar2(60); begin open c_dbnames; loop fetch c_dbnames v_curr_dbname; exit when c_dbnames%notfound; declare v_cursor integer; v_rows integer; v_curr_detail char(20); begin v_cursor := dbms_sql.open_cursor; dbms_sql.parse(v_cursor, 'select ''c_dbdetails'' c_dbdetails ' || v_curr_dbname, dbms_sql.native); dbms_sql.define_column_char(v_cursor, 1, v_curr_detail, 20); v_rows := dbms_sql.execute(v_cursor); loop if dbms_sql.fetch_rows(v_cursor) = 0 exit; end if; dbms_sql.column_value_char(v_cursor, 1, v_curr_detail); dbms_output.put_line('<tr><th>' || v_curr_detail ||'</th></tr>'); end loop; dbms_sql.close_cursor(v_cursor); end; end loop; close c_dbnames; end;
Comments
Post a Comment