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
     
  • 相关阅读:
    linux下启动和关闭网卡命令及DHCP上网
    python 编码问题
    paddlepaddle
    Convolutional Neural Network Architectures for Matching Natural Language Sentences
    deep learning RNN
    Learning Structured Representation for Text Classification via Reinforcement Learning 学习笔记
    Python IO密集型任务、计算密集型任务,以及多线程、多进程
    EM 算法最好的解释
    tensorflow 调参过程
    tensorflow 学习纪录(持续更新)
  • 原文地址:https://www.cnblogs.com/zy20160117/p/9336859.html
Copyright © 2011-2022 走看看