zoukankan      html  css  js  c++  java
  • oracle的spool功能

    如果表table1和table2中id值相等,那么用table1中的value值更新table2中的value值。

    下面是通过spool功能生成update语句脚本,可以创建*.sql脚本执行下面命令或者直接复制在command命令行执行。
    -------------------------------------------------------------------------
    set pagesize 0;     //输出每页行数,缺省为24,为了避免分页,可设定为0。
    set feedback off; //回显本次sql命令处理的记录条数,缺省为on
    set termout off; //显示脚本中的命令的执行结果,缺省为on
    set linesize 600 //输出一行字符个数,缺省为80
    col exportData for a1000;//指定列的长度超过1000则换行显示

    select 'prompt version 1.0' from dual;
    select 'SET DEFINE OFF' from dual;

    drop table temp_sxh;
    create table temp_sxh as with t1 as (
    select id as id,
      value as value
        from table1 a
        where a.id in (select id from table2))
    select a1, a2 from t1;

    spool E:work emp_sxh.sql;       //生成脚本路径和文件名,该命令放在要生成得到的语句前
    select 'update table2 a set a.value =' ||
       ''''|| b.value || ''''||
       'where a.id = '  ||
       ''''|| b.id ||''''|| ';' from temp_sxh b;

    drop table temp_sxh;

     select 'commit;' from dual;
     spool off;
     set termout on; //去除标准输出每行的拖尾空格,缺省为off

    --------------------------------------------------------------------
     此脚本执行后会生成temp_sxh.sql脚本文件,其中内容为:
     update table2 a set a.value ='100' where a.id = '100000';
     update table2 a set a.value ='101' where a.id = '100001';
     ....
     update table2 a set a.value ='101' where a.id = 'n00000';
     commit;

     如果没有关联信息,那么生成的temp_sxh.sql脚本文件,内容只有
     commit;
     
    //补充:
    set wrap on/off 查询返回的纪录每行超过默认宽度时,可选择换行(on )或不换行(off),默认为换行;
    prompt  打印输出功能,多用于提示信息;如 prompt  ‘aaa 命令执行成功!’,标准输出为:aaa 命令执行成功!
    set linesize 100 --输出一行字符个数,缺省为80
     
  • 相关阅读:
    理解Javascript_13_执行模型详解
    vs2005的快捷键
    去除 VS.Net 2003 项目的 VSS 息的脚本
    VS2005的隐藏快捷键
    程序员,你离坐牢还有多远
    对路径XXX的访问被拒绝(文件操作权限)的解决方法
    安装VS2005 SP1之后无法更改或卸载VS2005的处理方法
    强大的.NET反编译工具Reflector及插件
    反编译工具Reflector下载(集成两个常用.net插件,FileGenerator和FileDisassembler)
    两种彻底删除VIEWSTATE的方法
  • 原文地址:https://www.cnblogs.com/zy20160117/p/9336859.html
Copyright © 2011-2022 走看看