有没有办法将动态生成的 SQL 提交给 Teradata?我编写了一个查询,该查询将创建代码以对表进行非规范化。现在,我将代码拉到我的客户 (SAS) 并在第二步中重新提交。我对 Teradata 宏或程序都不熟悉;类似的东西会起作用吗?
为了说明,我有一个这样定义的表:
create multiset table MYTABLE
( RECID integer generated always as identity
( start with 1
increment by 1
minvalue -2147483647
maxvalue 2147483647
no cycle )
, SNAP_DATE date format 'YYYY/MM/DD'
, EMAIL_DATE date format 'YYYY/MM/DD'
, FREQ integer
)
unique primary index ( RECID )
该表每天都会填充 ( SNAP_DATE
),用于监控另一个表中 email_date 的更改。以下查询返回我可以运行以创建非规范化视图的代码:
select RUN_THIS
from (
select RUN_THIS, RN
from (
select 'select EMAIL_DATE ' (varchar(100)) as RUN_THIS
, 0 (int) as RN
) x
union all
select ', sum( case when SNAP_DATE = date '''
|| (SNAP_DATE (format 'yyyy-mm-dd') (char(10)) )
|| ''' then FREQ else 0 end ) as D'
|| (SNAP_DATE (format 'yyyymmdd') (char(8)) ) as RUN_THIS
, row_number() over ( partition by 1 order by SNAP_DATE ) as RN
from ( select distinct SNAP_DATE
from MYTABLE
where SNAP_DATE > current_date - 30) t1
union all
select RUN_THIS, RN
from (
select 'from MYTABLE group by 1 order by 1;' as RUN_THIS
, 10000 as RN
) y
) t
order by RN
我将上述查询的结果导出到客户端上的文件,然后转身将该文件提交回 Teradata。我希望有某种方法可以将这个完整的定义存储在某个 Teradata 对象中,以便可以直接执行。