execute immediate over database link

2019-04-13 05:19发布

Is it possible to execute dynamic PL/SQL on a remote database via a databse link?

I'm looking for something like:

l_stmt := 'begin null; end;';
execute immediate l_stmt@dblink;

The syntax above is obviously wrong, I get PLS-00201: identifier 'L_STMT@DBLINK' must be declared.

It is possible to create a procedure remotely and then execute it. Is there a way to execute code without creating a remote procedure?

EDIT: I'm trying to work around passing a type over DB link. A remote procedure requires a parameter of type t_id_tab which is defined on the remote DB as

CREATE OR REPLACE TYPE T_ID_TAB AS TABLE OF NUMBER(12)

4条回答
forever°为你锁心
2楼-- · 2019-04-13 05:34

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

ret := DBMS_SQL.EXECUTE(c);
查看更多
▲ chillily
3楼-- · 2019-04-13 05:47

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

查看更多
可以哭但决不认输i
4楼-- · 2019-04-13 05:56

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.

查看更多
Emotional °昔
5楼-- · 2019-04-13 05:56

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...

查看更多
登录 后发表回答