SELECT
'CREATE OR REPLACE VIEW ' || table_schema || '.' || table_name || ' AS ' ||
view_definition AS create_statement
FROM
information_schema.views
WHERE
table_schema = 'your_schema_name'
and table_name in ('your_view_name1','your_view_name2','your_view_name3');
需要替换:
your_schema_name :替换为你要提取视图的模式名称
your_view_name1 :替换为你要提取视图的名称1
your_view_name2 :替换为你要提取视图的名称2
your_view_name3 :替换为你要提取视图的名称3
解释:
table_schema :模式名称
table_name :视图名称
view_definition :视图的定义或查询语句
information_schema.views :视图来获取有关视图的详细信息
以下是 information_schema.views
中包含的一些列:
table_catalog
:包含视图所属的数据库名。table_schema
:包含视图所属的模式名。table_name
:包含视图的名称。view_definition
:包含视图的定义或查询语句。check_option
:如果使用 WITH CHECK OPTION 创建了视图,则此列包含 CHECK OPTION,否则为空字符串。is_updatable
:如果视图是可更新的,则此列包含 YES,否则包含 NO。