execute immediate over database link

試著忘記壹切 提交于 2019-12-04 17:46:55

You can execute arbitary code on the remote database by calling the DBMS_SQL package there.

Sample:

set serveroutput on

create or replace synonym remote_dbms_sql for dbms_sql@core;

declare
  c  number;
  l_global_name  varchar2(200);
begin
  c := remote_dbms_sql.open_cursor();
  remote_dbms_sql.parse( c, 'select global_name from global_name', dbms_sql.native );
  remote_dbms_sql.define_column( c, 1, l_global_name, 200 );
  dbms_output.put_line( remote_dbms_sql.execute_and_fetch( c ) );
  remote_dbms_sql.column_value( c, 1, l_global_name );
  dbms_output.put_line( l_global_name );
  remote_dbms_sql.close_cursor( c );
end;
/

Note that the reference to DBMS_SQL.NATIVE is local, not remote. You can't reference remote package constants, but presumably the actual value of this constant is the same in both databases.

I would think that you would just qualify the object names in the procedure, rather than qualifying the procedure itself.

prayash khadka

You are missing execute in above example. Please see below:

ret := DBMS_SQL.EXECUTE(c);

Have you tried to create the array on a package instead of a type? I mean:

CREATE OR REPLACE PACKAGE the_package AS
  TYPE T_ID_TAB AS TABLE OF NUMBER(12);
END the_package;

May be, with this way works, I've not tried...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!