Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > 特殊的insert语句(续)
【标  题】:特殊的insert语句(续)
【关键字】:insert
【来  源】:http://www.cublog.cn/u/22472/showart.php?id=239938

特殊的insert语句(续)

Your Ad Here
特殊的insert语句(续)
 
     作者:西方经济学(honghong)
     时间:2007-01-29 20:16:50
     版权所有,欢迎转载,需注明出处 http://hong.cublog.cn/,谢谢合作!
  
   在前面曾经讨论过oracle的特殊insert语句,今天介绍一下另外的比较特殊的insert语句。
 
   (1)、无条件的insert:用于将查询出的结果将相应的列向多表插入。
        

  insert all
    
        into sal_history values(empid,hiredate,sal)

        into mgr_history values(empid,mgr,sal)
     
  select employee_id empid,manager_id mgr, salary sal,

       

        hire_date hiredate

  from employees

  where employee_id>200;


 
   (2)、条件的insert:根据条件向不同的表插入不同信息。
 

  insert all
    
         when sal>20000 then

         into sal_history values(empid,hiredate,sal)
        
         when mgr>200 then
        
         into mgr_history values(empid,mgr,sal)

  select employee_id empid,manager_id mgr,hire_date hiredate,
    
         salary sal
          
   from employees

   where employee_id>200;

           
    (3)、有条件的 first insert:
 

   insert first
    
          when sal>50000 then
        
               into special_sal values(deptid,sal)

         when hiredate like ('%00%') then
        
               into hiredate_history_00 values (deptid,hiredate)

         when hiredate like ('%99%') then

               into hiredate_history_99 values (deptid,hiredate)

   select department_id deptid,sum(salary)sal,max(hire_date) hiredate
         
   from employees

   group by department_id


     (4)、行列转换的 insert:将多列数据转换成多行记录
     

  insert all

         into sales_info values (employee_id,week_id,sales_mon)

         into sales_info values (employee_id,week_id,sales_tue)

         into sales_info values (employee_id,week_id,sales_wed)

         into sales_info values (employee_id,week_id,sales_thur)

         into sales_info values (employee_id,week_id,sales_fri)

  selectemployee_id,week_id,sales_mon,sales_tue,sales_wed,sales_thur,sales_fri

  from sales_source_data

 

checkpoint 学习:【上一篇】
SQL Server日志清除的两种方法 (转):【下一篇】
【相关文章】
  • Oracle中特殊的INSERT语句
  • kaei OleInsertDialog
  • 为Windows Live Writer开发插件——InsertSearchPageLink
  • 发行版发布: INSERT 1.3.8a
  • 发行版发布: INSERT 1.3.8
  • array_insert.c
  • 如何用数据表对象生成 sql insert 命令
  • INSERT INTO语句中直接插入一条SELECT语句
  • Oracle的Nologging何时生效 与 批量insert加载数据效率
  • 从Oracle数据库中读取数据,自动生成INSERT语句
  • 【随机文章】
  • 计算机硬件常识
  • 提高Linux安全等级
  • 打造自己的CButton
  • 数据库(拷贝或移动列表框或组合框中的内容)
  • 浅析DSLAM的IP上联方式
  • 将人民币金额转换成大写的金额
  • 从UNIX系统获取密码档(一) 上
  • [MySQL中文文档]MySQL同步(三)
  • 代码分析技术---PE格式
  • 如何修改.cc文件为vc认识的c/c++文件
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.