SQL/PLUS学习笔记之ECHO和SPOOL的利用[Oracle防范]
本文“SQL/PLUS学习笔记之ECHO和SPOOL的利用[Oracle防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
上次我们介绍了:SQL/PLUS学习笔记之编辑缓冲区中的当前行号令,本文我们介绍一下SQL/PLUS学习笔记之ECHO和SPOOL的利用,接下来就让我们一同来理解一下这部份内容.
ECHO参数的设置:
SQL> show echo --显示echo的状况
echo OFF --此时echo是OFF状况
SQL> set echo on --设置其为开状况
SQL> show echo
echo ON --已经翻开
此时运行脚本的话,脚本中的每条SQL语句或PL/SQL块将会显示在终端,以下运行test脚本:
SQL> @test --其下面均为终端显示的内容
SQL> select *from t1 where rownum<2;
ID NAME
---------- --------------------
1 Testing
SQL>
SQL> truncate table t1;
Table truncated.
SQL>
SQL> begin
2
3 for i in 1 1000 loop
4
5 insert into t1 values(i,'Testing');
6 end loop;
7 commit;
8
9 end;
10 /
PL/SQL procedure successfully completed.
SQL>
SQL> select count(*)from t1;
COUNT(*)
----------
1000
利用SPOOL保存查询的后果集
SQL> spool outputfile --默许在当前途径下生成outputfile.lst文件
SQL> select * from t1 where rownum<3;
ID NAME
---------- --------------------
1 Testing
2 Testing
SQL> spool off --终止,此时这些内容全部被写入文件outputfile中
[oracle@localhost ~]$ cat outputfile.lst --查看文件内容以下:
SQL> select * from t1 where rownum<3;
ID NAME ---------- --------------------
1 Testing
2 Testing
SQL> spool off
这个功效可以帮忙生成一些动态的批量处理的脚本,比方说删除用户emcd下的满意某些条件的表:
SQL> show user
USER is "EMCD"
SQL> spool droptable.sql
SQL> select 'drop table'||objec_name from user_objects where object_type='TABLE';
select 'drop table'||objec_name from user_objects where object_type='TABLE'
*
ERROR at line 1:
ORA-00904: "OBJEC_NAME": invalid identifier
SQL> l
1* select 'drop table'||objec_name from user_objects where object_type='TABLE' SQL> c/objec_/object_
1* select 'drop table'||object_name from user_objects where object_type='TABLE' SQL> /
'DROPTABLE'||OBJECT_NAME
--------------------------------------------------------------------------------
drop tableT1
drop tableBIN$qokoVJ6g4HHgQAB/AQAzMg==$0
drop tableTOAD_PLAN_TABLE
SQL> l
1* select 'drop table'||object_name from user_objects where object_type='TABLE' SQL> c/'drop table'/'drop table '
1* select 'drop table '||object_name from user_objects where object_type='TABLE' SQL> /
'DROPTABLE'||OBJECT_NAME
--------------------------------------------------------------------------------
drop table T1
drop table BIN$qokoVJ6g4HHgQAB/AQAzMg==$0
drop table TOAD_PLAN_TABLE
SQL> spool off --完毕输入
SQL> !
[oracle@localhost ~]$ cat droptable.sql --查看输出内容,以下所示:
SQL> select 'drop table'||objec_name from user_objects where object_type='TABLE';
select 'drop table'||objec_name from user_objects where object_type='TABLE'
* ERROR at line 1:
ORA-00904: "OBJEC_NAME": invalid identifier
SQL> l
1* select 'drop table'||objec_name from user_objects where object_type='TABLE' SQL> c/objec_/object_
1* select 'drop table'||object_name from user_objects where object_type='TABLE' SQL> /
'DROPTABLE'||OBJECT_NAME
--------------------------------------------------------------------------------
drop tableT1
drop tableBIN$qokoVJ6g4HHgQAB/AQAzMg==$0
drop tableTOAD_PLAN_TABLE
SQL> l
1* select 'drop table'||object_name from user_objects where object_type='TABLE' SQL> c/'drop table'/'drop table '
1* select 'drop table '||object_name from user_objects where object_type='TABLE' SQL> /
'DROPTABLE'||OBJECT_NAME
--------------------------------------------------------------------------------
drop table T1
drop table BIN$qokoVJ6g4HHgQAB/AQAzMg==$0
drop table TOAD_PLAN_TABLE
SQL> spool off
这样动态删除某些表的SQL语句就生成了.
关于SQL/PLUS学习笔记之ECHO和SPOOL的利用的知识就介绍到这里了,但愿本次的介绍可以对您有所收获!
以上是“SQL/PLUS学习笔记之ECHO和SPOOL的利用[Oracle防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |