博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PLSQL_两表之间的相互操作
阅读量:7090 次
发布时间:2019-06-28

本文共 1134 字,大约阅读时间需要 3 分钟。

 一、从一个表插入到另一个表中

      表的插入操作,有时需要考虑到自增的情况,用到了nextval函数,然后利用 insert into table1 (....) select... from table2 的语法。注意select与()中的值 一 一对应。

      insert  into plan_target_run (spec_run_id, dept_id, cost_id, manage_id, attribute1, attribute2, attribute3,note, flag,last_update_date, last_updated_by)

      select plan_target_spec_run_s.nextval, t.dept_id, t.cost_id, t.manage_id, null,null, null,null, 0, sysdate, 1  from plan_target_library t  where t.dept_id=168875 and t.type_id=3

     上述语句是从plan_target_library表中插入相应的数据到plan_target_run中。

二、用一个表的数据更新另一表的数据

       从后台导入数据时,常常用到Excel格式导入,在建立临时表后,怎么把两个表对应起来是一个逻辑思考的问题。

       update plan_target_run t   set t.target_value = (select s.tempruntarget  from targetruntemp s  where s.temprunid = t.run_id)   where t.run_id in  (select s.temprunid from targetruntemp s where s.temprunid = t.run_id)

        上述中 select s.teamruntarget  from targetruntemp s  where s.temprunid = t.run_id   t.run_id是对表plan_target_run遍历过程中的某一个确定值,因此这条语句是一条记录。与select s.temprunid from targetruntemp s where s.temprunid = t.run_id一样  t.run_id是确定的,两者操作的是统一记录,获取不同的属性。

        多么复杂的关系,都记住常规语法,update table1 set table1.attribute=... where (条件)。

转载于:https://my.oschina.net/twenty/blog/285651

你可能感兴趣的文章
DesUtils工具类
查看>>
mysql中模糊查询的四种用法介绍
查看>>
使用jetty-maven-plugin插件进行测试
查看>>
swift 实践- 11 -- UISlider
查看>>
定制化自己的itchat
查看>>
爬虫之聚焦爬虫与验证码处理
查看>>
Codeforces Round #376 (Div. 2) C D F
查看>>
聪聪可可【国家集训队】
查看>>
二维数组的连续子数组的最大和
查看>>
PHP无限级分类-递归(不推荐)
查看>>
PHP json_encode自动转码的问题
查看>>
LINQ to Entities 查询注意事项
查看>>
nginx + supervisrd + gunicorn + Flask
查看>>
Android 音视频深入 三 MP4解码播放视频 (附源码下载)
查看>>
二月场爆破-3
查看>>
Python之路——琐碎知识
查看>>
bootstrap-滚动监听
查看>>
java判断字符串中是否含有中文
查看>>
(zz)数据库设计中的14个技巧
查看>>
第三周作业
查看>>