Friday, July 8, 2011

Can a macro be called inside a macro?

Answer:
The main purpose of run a set of repeated sql queries.   Macro supports only DML queries .
Hence We cant call any-other macro or not even a procedure in a macro.

One trick to have closest functionality of this is to copy all the sql queries from macro2 to macro1 and add parameters if it is necessary as shown below.


replace macro1( val int)
as
(  sel * from employee_table where empid= :val );

replace macro2( dept_no int)
as
(  sel * from employee_table where deptno= :dept_no );

so, to call a macro2 inside a macro1..it is not possible. Hence follow this approach

Replace macro1 (val int, dept_no int)
as
(
sel * from employee_table where empid= :val;
sel * from employee_table where deptno= :dept_no ;
);

2 comments:

  1. Thank you very much vinay....for all ur posts

    ReplyDelete
  2. Hi Vinay,
    We can call a macro from another macro.. it works pretty well...but the only constraint is passing the values to host variables of 2nd macro.

    So, this logic works only if there are no parameters to be passed to the 2nd macro

    ReplyDelete