通常要单独在OS后台执行一个耗时的SQL脚本,采用如下两种方法:
方法一:
1、在其目录创建一个可执行脚本,如脚本名为 create_index.sh:
$vi create_index.sh
2、编辑文件内容:
sqlplus username/password <<EOF --注: 表示连接 到oracle, EOF表示下面这段内容的开始 /* * 这儿添加想要执行的SQL文本 * 如: */ create index idx_test01 on test(id); EOF --注:表示结束 end of file ,
3、赋予该文件的可执行权限:
$chmod 777 create_index.sh
4、在后台执行,并将执行日志重定向到一个日志文件:
$nohup ./create_index.sh >create_index.log &
5、查看执行情况:
$ps -ef | grep create_index.sh或
$jobs
方法二:
1、编辑要执行的SQL文件
$vi test.sql输入如下内容
select * from dual; select * from dba_objects where rownum<=10;
2、在后台执行
$ nohup sqlplus / as sysdba @/home/oracle/test.sql &
3、查看执行情况:
$jobs