You are on page 1of 1

Macros are a bunch of SQLs bundled together , provides transactional integrity (

all the sqls in the bundled is considered as part of a single transaction), conv
enience (you can parameterize frequent sqls, no need of typing again and again),
security (access given only to macros which has logic to do only specific opera
tions on the target objects), performance (you have already compiled in all the
code in the database, reduces the client-server interaction, suits real time / t
actical requirements) .. etc

CREATE MACRO vinay


AS (
INSERT INTO retail.mahi1
values(231124,
731121,
47113282,
9611123);
select * from retail.mahi1;
delete from retail.mahi3;);
To execute macro
syntax:exec macroname;
To drop macro
syntax:drop macro macroname;
/*create parameterised macro*/
create macro manish(l_orderkey1 integer)
as (select * from retail.item where l_orderkey=:l_orderkey1;)
exec manish(2)
drop macro manish
replace macro manish(l_orderkey1 integer,l_partkey1 integer)
as (select * from retail.item where l_orderkey=:l_orderkey1;)
exec manish(3853,338)

You might also like