Search notes:

Oracle: SQL macros

Two types of SQL macros

There are two types of SQL macros:
Their main difference is that
These types are declared with a sql_macro_clause as part of a create function statement:
function XYZ(…) return varchar2 sql_macro(table ) …
function XYZ(…) return varchar2 sql_macro(scalar) …
function XYZ(…) return varchar2 sql_macro         …
Without explicitly stating sql_macro with either table or scalar, the function defaults to a table macro.

Definition and declaration in a package

When unsing SQL macros in a package, the keyword sql_macro appears in the package specification …
create or replace package tq84 as

    function find (
        pattern    varchar2,
        typ        varchar2
    ) return varchar2 sql_macro;

end tq84;
/
… but not in the body:
create or replace package body tq84 as
…
    function find (
        pattern    varchar2,
        typ        varchar2
    ) return varchar2 is
    begin
       return q'{
          select *
          from
             syz v
          where
             v.typ = find.typ and
             regexp_like(v.text, find.pattern, 'ni')
       }';

    end find;

end tq84;
/

Simple example

A basic example for SQL macros is here.

Misc

ORA-64630: unsupported use of SQL macro: use of SQL macro inside WITH clause is not supported

See also

Some investigations on using function parameters in SQL macro functions.
PL/SQL functions and procedures

Index