Skip to content

Instantly share code, notes, and snippets.

@mvelikikh mvelikikh/sql_macro_19_6_20200129.sql Secret
Last active Jan 29, 2020

Embed
What would you like to do?
drop table t;
drop table t1;
drop table t2;
CREATE OR REPLACE FUNCTION sample(t DBMS_TF.Table_t, how_many number DEFAULT 5)
RETURN VARCHAR2 SQL_MACRO
AS
BEGIN
RETURN q'[SELECT *
FROM t
WHERE rownum <= how_many]';
END sample;
/
create table t
as
select n
from xmltable('1 to 10'
columns
n int path '.');
create table t1
as
select n,
'val_'||to_char(n, 'fm00') val
from xmltable('1 to 10'
columns
n int path '.');
create table t2
as
select 'val_'||to_char(n, 'fm00') s
from xmltable('1 to 10'
columns
n int path '.');
select * from t1;
select * from t2;
select *
from sample(t1, 3);
select *
from sample(t1);
select *
from sample(t2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.