首页 > Linux操作系统 > Linux操作系统 > SQL角本-建物化视图
目的:对某表创建物化视图时,不要求它所有字段,因此必须列出要的字段,一个个字段COPY也比较麻烦.因此写一角本
select
' create materialized view ' || max (a.table_name) || chr( 10 ) ||
' tablespace staging refresh fast as select ' || chr( 10 ) ||
substr( max (sys_connect_by_path(a.column_name || chr( 10 ), ' , ' )), 2 ) ||
' from ' || max (a.table_name) || ' @zhengguan t; ' -- 这里是DBLINK
from
( select row_number() over ( PARTITION BY g.table_name order by g.column_id ) rn
,g.table_name,g.column_name from
user_tab_cols g
where g.table_name = ' TB_LVY_INCREASEDECREASEDATA ' -- 这里是要建的表名
) a
start with rn = 1
connect by rn = prior rn + 1 来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/134308/viewspace-140594/ ,如需转载,请注明出处,否则将追究法律责任。