Link to home
Start Free TrialLog in
Avatar of TOWELLR
TOWELLR

asked on

plsql execute remote procedure over dblink with variables

I am trying to execute a procedure on a remote database across a dblink passing in variables that will select into another variable.  I know it needs to use execute immediate but the syntax is getting the best of me.

FUNCTION check_capture (p_capturename IN varchar2, p_site IN varchar2)
   RETURN varchar2
   IS
   p_capturestatus varchar2(20);
   v_ddl varchar(256);


   BEGIN
   
     v_ddl:= 'begin select status from dba_capture@'||p_site||' where capture_name ='||''''||p_capturename||''''||'; end;';
   
    DBMS_OUTPUT.put_line(v_ddl);

     execute immediate v_ddl into p_capturestatus;
 
   
      RETURN(p_capturestatus);

    END CHECK_CAPTURE;

If I run this in sqlplus I get the following:

SQL> select cdc_monitor.check_capture('CDC$C_TRACE3D2','TRACE3D2') from dual;
select cdc_monitor.check_capture('CDC$C_TRACE3D2','TRACE3D2') from dual
       *
ERROR at line 1:
ORA-20001: An error was encountered - -6550 -ERROR- ORA-06550: line 1, column 7:
PLS-00428: an INTO clause is expected in this SELECT statement
ORA-06512: at "CDCADMIN.CDC_MONITOR", line 23


begin select status from dba_capture@TRACE3D2 where capture_name ='CDC$C_TRACE3D2'; end;
sql>

The dbms_output looks ok but it keeps bombing on the INTO clause.

Any suggestions for a better way to write this?
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TOWELLR
TOWELLR

ASKER

I was just removing the begin and end.
That seemed to be my major issue.
Thanks for the quick response.

I think the bind variable method is a bit cleaner so I may use that as well.
>>I think the bind variable method is a bit cleaner so I may use that as well.

It also saves you from SQL Injection.