Search notes:

Oracle: Table macros

The value passed to a table macro can appear in the returned select statement anywhere where also a bind variable might be placed.
create or replace function tq84_table_macro(p varchar2) return varchar2 sql_macro(table)
is begin
 
   return q'{

       select
          object_name,
          p
       from
          user_objects
        where
          object_name like upper('%' || p || '%') 
   }';

end tq84_table_macro;
/

select * from tq84_table_macro('du');

Parameter is NULL outside of the returned SQL text

Outside of the returned SQL text, the parameter(s) is null.
create or replace function tq84_table_macro(p varchar2) return varchar2 sql_macro(table)
is
   col_alias varchar2(128);
begin

   col_alias := nvl(p, 'p_is_null');
   
   return '

       select
          ''returned value'' as ' || col_alias || '
       from
          dual';

end tq84_table_macro;
/

select * from tq84_table_macro('non_null_value');
-- P_IS_NULL     
-- --------------
-- returned value
A consequence of this is that it is not possible to return a fundamentally different SQL text depending on the value passed to the function when it was invoked.

See also

SQL Macros

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758198567, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/PL-SQL/function-procedure/sql_macro/table/index(85): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78