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
SQL macro functions cannot be compbined with the authid clause.

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...', 1758199934, '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/index(107): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78