今天学习exp和imp,虽然之前有所了解,但是实际操作很少,不够熟练,而且没有imp的经验,于是首先进行了exp的操作
exp zyp/zyp@yp file=f:\exp_200921.dmp wner=zyp
完成之后 想要实验一下 实际的效果,于是想到把zyp用户下的表全部给删除掉,一个一个删除实在太慢,而用||连接符号到时很快 但是还需要执行语句之后执行删除的语句,
select 'drop table '||table_name ||';' from user_tables.
能不能用动态语句直接执行呢?
答案当然是肯定的了,经过实验 脚本如下:
SQL> declare t1 varchar2(30) ;
2 cursor t2 is select table_name from user_tables;
3 begin
4 open t2;
5 loop
6 fetch t2 into t1;
7 exit when t2%notfound;
8 execute immediate 'drop table '||t1||'';
9 end loop;
10 end;
11 /
PL/SQL 过程已成功完成。
SQL>SQL> select count(*) from user_tables;
COUNT(*)
----------
0
SQL>
删了个一干二净啊,要不是为了测试一下imp,顺便熟悉一下PLSQL的使用, 打死我也不敢执行这种语句,自己的测试数据库就无所谓,如果是其他的库即便是加where条件我也不敢执行。
主要是为了学习,下面导入.dmp 文件试试
imp zyp/zyp@yp file=f:\exp_200921.dmp full=y
完成之后
SQL> select count(*) from user_tables;
COUNT(*)
----------
70
SQL>
哈哈 失去的表又回来了。
另附一个循环建表的plsql语句
declare t1 number;
begin
for t1 in 1..10 loop
execute immediate 'create table YP_'||t1||' (tt number)';
end loop;
end;
/
exp zyp/zyp@yp file=f:\exp_200921.dmp wner=zyp
完成之后 想要实验一下 实际的效果,于是想到把zyp用户下的表全部给删除掉,一个一个删除实在太慢,而用||连接符号到时很快 但是还需要执行语句之后执行删除的语句,
select 'drop table '||table_name ||';' from user_tables.
能不能用动态语句直接执行呢?
答案当然是肯定的了,经过实验 脚本如下:
SQL> declare t1 varchar2(30) ;
2 cursor t2 is select table_name from user_tables;
3 begin
4 open t2;
5 loop
6 fetch t2 into t1;
7 exit when t2%notfound;
8 execute immediate 'drop table '||t1||'';
9 end loop;
10 end;
11 /
PL/SQL 过程已成功完成。
SQL>SQL> select count(*) from user_tables;
COUNT(*)
----------
0
SQL>
删了个一干二净啊,要不是为了测试一下imp,顺便熟悉一下PLSQL的使用, 打死我也不敢执行这种语句,自己的测试数据库就无所谓,如果是其他的库即便是加where条件我也不敢执行。
主要是为了学习,下面导入.dmp 文件试试
imp zyp/zyp@yp file=f:\exp_200921.dmp full=y
完成之后
SQL> select count(*) from user_tables;
COUNT(*)
----------
70
SQL>
哈哈 失去的表又回来了。
另附一个循环建表的plsql语句
declare t1 number;
begin
for t1 in 1..10 loop
execute immediate 'create table YP_'||t1||' (tt number)';
end loop;
end;
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12216142/viewspace-573327/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12216142/viewspace-573327/