I'm Chris :)
So is it like SQL_MACRO is designed only to take in INT, DATE ? No! String parameters are valid. The problem is how you're using these parameters in the macro.
You should use parameters to SQL macros as placeholders in the return string. Keep any logic in the body of a macro to a minimum (ideally none). This applies to parameters of all data types.
The body of the macro is only executed when parsing the query. This means you're not guaranteed to see data changes if you have queries inside it.
For example, this counts rows in T inside the macro and is the return template. Notice that adding more rows does not affect the value of C fetched inside the function:
create table t ( c1 int );
create or replace function f ( p int )
return clob sql_macro as
c int;
begin
select count(*) into c from t
where c1 = p;
return '
select ' || c || ' as c, count(*)
from t where c1 = p ';
end;
/
insert into t values ( 1 );
commit;
select * from f ( 1 );
C COUNT(*)
---------- ----------
1 1
insert into t values ( 1 );
commit;
select * from f ( 1 );
C COUNT(*)
---------- ----------
1 2