NZPLSQL Unnamed blocks

CREATE SEQUENCE sq_unnamed_blocks AS INTEGER
START WITH 1 INCREMENT BY 1;

CREATE OR REPLACE PROCEDURE pr_unnamed_blocks(
TEXT
)
RETURNS INTEGER EXECUTE AS CALLER LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
loc_run ALIAS FOR $1;
loc_name TEXT;
loc_body TEXT;
BEGIN
loc_name := ‘pr_unnamed_block_tmp_’ || CAST((NEXT VALUE FOR sq_unnamed_blocks) AS VARCHAR(38)) || ‘()’;
loc_body := ‘CREATE OR REPLACE PROCEDURE ‘ || loc_name || ‘ RETURNS INTEGER LANGUAGE NZPLSQL AS BEGIN_PROC ‘ || loc_run || ‘ END_PROC;’;
EXECUTE IMMEDIATE loc_body;
EXECUTE IMMEDIATE ‘CALL ‘ || loc_name;
EXECUTE IMMEDIATE ‘DROP PROCEDURE ‘ || loc_name;
RETURN 0;
END;
END_PROC;

EXECUTE pr_unnamed_blocks(
BEGIN_PROC
DECLARE
i INTEGER DEFAULT 0;
BEGIN
i := i + 1;
RAISE NOTICE ‘i = %’, i;
END;
END_PROC
);

EXECUTE pr_unnamed_blocks(

DECLARE
i INTEGER DEFAULT 0;
BEGIN
i := i + 1;
RAISE NOTICE ”i = %”, i;
END;

);