Showing posts with label DDL. Show all posts
Showing posts with label DDL. Show all posts

Monday, October 22, 2012

Execute DDL statement over dynamic DB link


If you want to execute DDL statement <sql_statement> over DB link <db_link_name> try using this:


  DECLARE
    t_cursor PLS_INTEGER;
  BEGIN
    t_cursor := dbms_sql.open_cursor'||db_link_name||';
    dbms_sql.parse'||db_link_name||'(t_cursor, '''||sql_statement||''', dbms_sql.NATIVE);
    dbms_sql.close_cursor'||db_link_name||'(t_cursor);
  END;

This solution is quite tricky and I guess this wouldn't work for every DDL statement but it worked for me in 10g for enabling/disabling constraints and indexes. Another good thing about it is that DBlink name is dynamic and not hard-coded.