此查询只生成语句,用户通常必须通过脚本、手工活其他执行sql语句的方法来执行这些语句。
一、生成sql来计算所有表中的行数
select 'select count(*) from '|| table_name ||';' cnts from user_tables
二、禁用所有表中的外键
select 'alter table '|| table_name || ' disable constraint '||constraint_name||';' cons
from user_constraints where constraint_type='R';
三、根据表emp中的某些列生成插入脚本
select 'insert into emp(empno,empname,hiredate) '||chr(10)||
'values('||empno||','||''''||ename||''',to_date('||''''||hiredate||''') );' inserts
from emp where deptno='10'
单引号的转义请参考:
http://blog.csdn.net/chen_linbo/article/details/6334955
使用sql来生成sql语句在创建可移植脚本方面非常有用,执行批量维护也非常方便